DEV Community


Posted on

Create a cool discord bot for your chat group


It's very common to see that some discord groups add a discord bot. What does discord bot can do for us? It can reply to user depends on what they send。 Let's say when our users send some sad words the bot can encourage she/he by sending some words. Furthermore, when a new member joined our group, the bot can welcome the newcomers because the owner maybe not always online. The bot is scalable you can use it to create something awesome.


After searching GitHub i found out several discord Api libraries.

  • Cog-Creators/Red-DiscordBot(python)
  • discordjs/discord.js(javascript)
  • Rapptz/
  • bwmarrin/discordgo(golang) I choose Rapptz/ in this piece, because i damn love python。

Install env

First and foremost, we need to install our python env. We need to install python 3.8 or higher version. If you don't wanna to install any local env, that'sthat's ok you can use some cloud env like or pythonanywhere whatever you want. But for me i installed env using anaconda software. It provides UI and it's quite easy to use。

get a bot token

For sure we need a token。 Then how do we get it? Just click "" and then login your discord account. You will see the new application button near your avatar. After creating an application go to bot page and copy your token. You should be very careful not to leak it。

invent bot to our chat group

I hope you have a free discord chat group already。 If not, you can create one for free。Go to our application page again, you will see Oauth2/URL Generator。 Generate an invite link for your application by picking the scopes and permissions it needs to function。 Get the URL and open it in our browser。That's all。

Some awesome python code

import discord

class MyClient(discord.Client):
    async def on_ready(self):
        print('Logged on as', self.user)

    async def on_message(self, message):
        # don't respond to ourselves
        if == self.user:

        if message.content == 'ping':

intents = discord.Intents.default()
intents.message_content = True
client = MyClient(intents=intents)'YOUR TOKEN HERE')
Enter fullscreen mode Exit fullscreen mode

If you need a proxy you can attach some code like this

client = MyClient(intents=intents, proxy="")
Enter fullscreen mode Exit fullscreen mode

This proxy address is my local proxy address. You should replace it with your own address if you wanna use a proxy.


After you run python you will see

2022-09-30 10:15:48 INFO     discord.client logging in using static token
2022-09-30 10:15:50 INFO     discord.gateway Shard ID None has connected to Gateway (Session ID: xxxxxxx).
Logged on as xxxx-demo#4518
Enter fullscreen mode Exit fullscreen mode

After all of above is done you will see your bot is online。
If you get any question about discord bot or discord application please feel free to connect me.

Top comments (0)