paint-brush
Building Your Own Discord Bot With Python Is Easy by@gfrkad
214 reads

Building Your Own Discord Bot With Python Is Easy

by gfrkad.pyMay 30th, 2021
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

The bot will be made in python so make sure you have python installed. The bot responds to commands that follow the prefix ( for example:.hi runs the command “hi” only when it is preceded by the prefix). The commands that our bot sends in response to the command:.sup. The commands::reply2, emoji, image, and help are optional arguments that you can provide. The code for the bot is 4 lines of code and you can run it on the discord discord server.
featured image - Building Your Own Discord Bot With Python Is Easy
gfrkad.py HackerNoon profile picture

This Bot will be made in python so make sure you have python installed. you can install python here.

Open command prompt and type the following :

pip install discord-bot-maker

This will install the required modules.

Go to Discord Developer Portal and create an application by clicking on “New Application” and then follow the steps given here.

Copy the TOKEN and save it somewhere. We will need it later in this tutorial.

Open a text editor of your choice(or open IDLE if you are a beginner)

We will now start writing the code for our bot

1. Import the required module

from discord_bot_maker import DBot

2. Create an instance of the DBot object which allows us to create commands that our bot can respond to

d = DBot("PREFIX", "TOKEN")

Replace PREFIX with a prefix of your choice ( for example: .) and TOKEN with the TOKEN that we saved before.

NOTE: The bot responds to commands that follow the prefix( for example: .hi runs the command “hi” only when it is preceded by the prefix).

3. Create your command using the arguments provided.

d.createCommand(trigger = "sup", reply = "I am fine", reply2 = "What about you?", emoji = "😄", image = "sup.gif", help = "replies with 'I am fine'")

trigger is the message that triggers this command(.sup)

reply specifies the message that our bot sends in response to the command. Here, “I am fine” is sent.

reply2, emoji, image, and help are optional arguments that you can provide.

4. Run the bot

d.bRun()

Here is the entire code:

from discord_bot_maker import DBot

d = DBot("PREFIX", "TOKEN")

d.createCommand(trigger = "sup", reply = "I am fine", reply2 = "What about you?", emoji = "😄", image = "sup.gif", help = "replies with 'I am fine'")

d.bRun()

Congratulations!

You just made a discord bot in 4 lines of code!

Run the code and have fun with your bot. 😄

You can find more information about this module on pypi.

Join the discord server here

Also published on Medium's gfrkad