How to create a team management bot for Discord
Part 1: Set up the bot and add commands
Discord is usually the tool of choice for team communication — plus it’s free.
But are you constantly getting pinged by teammates with requests for event information or basic links? Getting asked the same question by multiple people?
Ever wished you could have your very own MinionBot to deal with it?
Well, now you can create your very own bot on Discord to manage events, meetings, attendance, and other important details! For the purpose of this tutorial, we will be focus on bot set up, connect it to a repl.it server, and add some basic commands. Part 2 of this tutorial will be posted shortly.
Learning Objective:
- Create a discord bot to manage team events, meetings, agendas, and attendance
- Host bot on the cloud for free
- Understand how to work with Python in Repl.it
What we will use:
- Discord API and Python Libraries
- Repl.it, a free collaborative IDE (integrated development environment)
- Uptimerobot, a free monitoring service
Step 1: Create the Discord bot account
- Log into Discord website.
- Go to the Developers Application page.
- Click New Application.
- Type the name of the application.
- Click Create.
5. Navigate to the bot tab and click Add Bot .
Note: Keep the bot public. Do not select any authorization protocol, so don’t request OAuth2.
6. Copy the token.
7. Save the token.
Step 2: Add bot to the Discord server
- Go to OAuth tab and click Bot in the Scopes panel.
2. Select the permissions as indicated in the screenshot provided.
3. Copy the link above the permissions.
4. Paste the link to your browser and authorize your bot to enter the Discord server.
Step 3: Connect bot to Repl.it and send a message
- Go to Repl.it and start a new Python project.
2. In main.py, import discord, OS, and commands API for Discord. This allows you to connect with the Discord bot.
import discord
import os
from discord.ext import commands
3. Add the Discord Bot token saved from earlier into the environment variables in Repl.it.
4. Initiate the Discord bot by adding this code.
bot = commands.Bot(command_prefix="$")# COMMANDS CODE GOES HEREbot.run(os.environ['TOKEN'])
The command_prefix variable sets the bot to recognize any message starting with $ as a command. You can change this to any prefix you prefer.
5. Create your first command by adding the following code above the bot.run() line.
@bot.command()
async def hello(ctx):
await ctx.channel.send("Hello!")
6. Run the Repl.it and test your code in your server. Typing $hello displays a response from your new Discord bot.
Step 4: Set up the Bot to run continuously
Note: At this point, you might notice that when you stop running the repl.it or close the tab, you lose all functionality in the bot. To make the bot usable, you must run it continuously. There are many different ways you can do this, but for this tutorial, we will be running it on a Repl.it webserver. Repl.it allows you to create a free webserver, but after 1 hour of inactivity, it shuts down. To keep the Repl.it server running, we must set up a virtual monitor using Uptimerobot.
- Create a new file in your repl.it called keep_alive.py and add the code provided in the screenshot.
from flask import Flask
from threading import Thread
app = Flask('')
@app.route('/')
def home():
return "Hello. I am alive!"
def run():
app.run(host='0.0.0.0',port=8080)
def keep_alive():
t = Thread(target=run)
t.start()
2. Add the following line to the bottom of your code right before the bot.run() command:
keep_alive()
3. Add the following line at the top of your code with the other import statements:
from keep_alive import keep_alive
4. Copy the URL at the top of the console window
5. Create a free account on https://uptimerobot.com/.
6. Log in to uptimerobot.com.
7. Click Add New Monitor.
7. Complete the following information in the form:
a. Choose HTTPS as the monitor type.
b. Paste the repl.it webserver link from earlier into the URL field.
c. Change the monitoring interval to be 30 mins.
8. Create the Monitor and rerun your repl.it. Now you should be able to use the bot whenever you wish without having to keep the repl.it tab open.
Final Note
If you are having any trouble with this code, please leave a comment below and I will get back to it as soon as possible. Additionally, if you would like to view the full code, here is the link to the corresponding GitHub repository: https://github.com/yoshighosh/SampleBotCode