Create a discord bot using Python
To make the bot that you will be using go to: https://discord.com/developers
Sign in to your discord account
Create a new application
Click the "bot" tab
Finally, give your bot a name.
Follow this tutorial to get started
If you want you bot to be online and responsive 24/7 i suggest hosting a web server on repl.it, it's very reliable and free.
The most useful tools are the commands and events, learning about commands and events is essential in creating a discord bot.
If you followed the video, skip these steps.
first you have to import commands:
from discord.ext import commands
next you need to create the client variable, this is how you call certain discord specific functions. which can be done by adding:
client = commands.Bot(command_prefix = 'your-prefix-here')
The prefix is what is going to use to call commands for example "!help" will call the "help" command. so make sure to change that.
next we need to create something to let us know the bot is working. So we are going to use the "on_ready" event.
@client.event
async def on_ready():
in the first line you are calling an event, and in the second line you are defining what triggers the following code, in this case the trigger is when the bot is ready.
Now is where you should add:
print('bot is ready')
if you know python, this is self explanatory, if you don't get this then go back and refresh your memory about python, because it get more confusing moving forward.
The last step to create a working bot is to add a "client.run" function to the end of you code. You do need a token to connect you script to the actual discord bot you created earlier.
You can find the token under the username through the bot tab in your dev portal. Once you do that, your code should look like this.
client.run('token')
We are going to create a basic command that send a message when executed.
To start off, we need to add
@client.command()
next we need to define the function so we add:
async def ping(ctx):
ctx is a required parameter for all commands, we will be using it later.
just like a regular function, what follows is the code that you want to be executed, you can run anything you want.
To send a message add:
await ctx.send('variable or string')
The possibilities are endless, find tutorials and keep experimenting.
A link to the documentation can be found here.
The documentation is the guide to the discord.py api. It's very helpful when developing a discord bot.
Good luck