Create Your Own Discord Bot

💡 This post is insightful for the following scenarios.

  • Create a discord bot

Background

To set up a assisting robots to help me obtain information.

Step

0. Preparation

You should:

  • have a discord accound
  • have a python environment

1. Create a discord bot

1.1 Enter discord application page

1.2 Click “New Application”

1.3 Give it a new name

1.4 Get your discord bot token

Enter Bot page

At the beginning, you need to click the “Reset Token” button to gain your first token. You should safely store it because anyone who owns this token can control its corresponding bot. We will use it in Step 4 Make the first move.

If you feel unncomfortable, you can reset your token at any time.

2. Add you discord server

This server is the place that you can put your dicord bot in.

3. Add your bot into your server

Set your application as a bot.

Assign it corresponding permissions. And copy the link.

Go to the link, select your server and authorize it.

Now you have your offline server bot.

4. Make the first move

Your have already created a bot and assign it into your server. And you have your bot token saved in step 2. Now you can teach your bot to make the first move.

Create this python file and run it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import discord

client = discord.Client(intents=discord.Intents.default())

@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
if message.author == client.user:
return

if message.content.startswith('$hello'):
await message.channel.send('Hello!')

# Assume your token is "abc456DEF".
token = "abc456DEF"

client.run(token)

And now Jarvis is online.

Then the bot will reply you “Hello!” when you say “$hello” to it.

5. Improvement

Now, you have create your bot. What you can do next is to create a new world!

For more information, you can check the discord official doc.