![]() Then go to Discord and send "Hi" to see the magic unfold. Now run the Python script in your terminal. Note that custom commands are Python functions: import discordīot = commands.Bot(command_prefix= def Hi (ctx):Īwait ctx.send( "Hi, welcome to our server") Using the decorator, let's make a custom command, Hi, and provide a reply text for the Discord bot when it sees it. So you don't need one while instructing the Discord bot. Characters like the dollar sign ($), exclamation (!), ampersand (&), and more are common prefixes that precede bot commands.īut we've blanked the prefix in our case. And the command_prefix in the parenthesis lets you specify a character that precedes it. The bot variable invokes custom commands from the command class. #Read your bot token from the txt file in your project root: # Initialize the bot instance and use a blank prefix: Here, you'll program your Discord bot to reply with a custom message when you send a text in a channel.īut first, type the following code at the top of your script to initialize your Discord bot: import discord ![]() With the virtual environment active, run the following command in your terminal to install these packages: pip install -U discord. Then activate a Python virtual environment.Īlso, you'll have to install discord.py and a voice support package called discord.py. If Python is up to date, open the terminal to your project root. You can check the Python version installed on your PC by entering the following command in your terminal: python -version If you've not done so already or have an earlier version, go to to download the latest Python version. To program your Discord bot with Python, you'll use the discord.py module, which only works with Python 3.5.3 or later. You can host yours on cloud services like Heroku if you want once everything is set up. Here you’ll want to select the server you’re adding your bot to, double-check the permissions you’re giving your bot, and then continue to the next step.For this tutorial, we'll use Python and host the Discord bot on the local machine. Go to that URL and you’ll see a page that looks sort of like this (see below). This is the URL you’ll navigate to in order to add your bot to a server. Only give your bot the permissions it really needs, that way you lower the risk of compromising your server.Īfter you’ve selected your permissions, scroll up a little bit and look at the URL that was generated.Ĭlick the blue “Copy” button on the right side. Your permissions are the second line of defense in case somebody gets their hands on your bot token. ![]() Important: Do not select all of the permissions “just to make things easy”. This is where you choose what permissions to give your bot, and what it can and can’t do.īased on what type of bot you’re planning on building, you’ll want to select permissions that most closely match what it’ll be doing day-to-day. ![]() Scroll down some more to the “Bot Permissions” section. You’ll notice that a URL appeared as soon as you clicked “bot” - this will be your URL for adding your bot to a server. In the “Scopes” section, you’ll want to select the “bot” checkbox. Once there, scroll down to the “Oauth2 URL Generator” section. In order to add your bot to your Discord Server, you’ll need to navigate back to the “OAuth2” tab. As soon as you click this link, your token will be revealed…Ī natural next step, however, is to add your bot into your Discord Server.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |