Learn to Code via Tutorials on Repl.it!

← Back to all posts
DISCORD.PY TUTORIAL [POG] MAKE YOUR OWN DISCORD BOT!! [POG]
elipie

Hello peoples

Today I will be teaching you some discord.py stuff. Its gonna be epiiccc!!

Lets get into it :))

Number one VERY IMPORTANT

Create an app then make bot.

Learn more here < pls go to that link its really important

Lets get started! Make a folder named src, and create two files named: bot.py and keep_alive.
Write the following code in main.py:

Yay you just imported those files from the src folder!

Lets go into the FUN stuff.

Oh wait nevermind, we need the .env!
Create a file called .env. Write this in your .env:
token=YourBotTokenHere
IMPORTANT: IT DOESN'T HAVE TO BE IN THE FOLDER

If you do not know how to get your bot token go here.

Lets go in bot.py, and setup our starter framework! Yes our prefix will be ~

Woah that was a lot
Lets break it down

  • First, Gets token with token = os.environ.get("token")
  • Second, It defines client and botname
  • Third, Creates the function on_message
  • Fourth, Checks if the author is the user not the bot, with if message.author == client.user:
  • Fifth, if the message starts with the command ~help, then do the following:
    • Create the variable msg.
    • Send the message.(await message.channel.send(msg))
  • Sixth, create the function on_ready
  • Log the ID and the NAME
  • Run the commands on the bot.

and that was a lot to recover

Review

  • How do you send a message?

Answer: First define the msg, then await (NOTE: MAKE SURE YOU ALWAYS HAVE THE await) after that, message.channel.send(msg).

  • How do you run the commands?

Answer: client.run(token)

Keep Your Bot alive!

🎵 Stayin Alive 🎵

Add this into keep_alive.py.

Part Two: Adding More Commands

Now that bot is BORING, Lets add some more!

Random "Hello" message!

Summon Command!

Deleting a Message

Alrighty, this is where some powers come in:
Your bot needs to have permissions! The way I do it is:
Make a bot role. Give the bot role administrator so they can delete messages.
OR...
You can give them permissions on your app! (AOUTH > that box at the buttom)

This can be most useful with nono words.

Check if the command is a actual command

We are going to have to add some stuff before we do this. Create a list with all the command names:
commands = ['hello', 'summon', 'delete'] #more commands

Review

  • How do you delete a message?

Answer: You must await message.delete()

Links:

Make app IMPORTANT
Get Bot Token
Keep Alive Tutorial

Credits

These people helped me make my first discord bot:
@Coder100 - giving me the run forever tutorial
@CoolJames1610 - Teaching me how to send message.

Tanks

Suggestions? Comments? PUT THEM IN THE COMMENTS!!!

kthxbai

Voters
KitKatKiddo
programmeruser
OskarasPreidius
adsarebbbad
HENRYMARTIN4
elipie
Comments
hotnewtop
TsunamiOrSumth

i have a suggestion; make the title

DISCORD.PY TUTORIAL [POG] MAKE YOUR OWN DISCORD BOT!! [POG]

elipie