Building Your Own Discord Bot With Python Is Easy

Written by gfrkad | Published 2021/05/30
Tech Story Tags: python | python-programming | discord | bot | bots | easy-to-understand | code | create

TLDR 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.via the TL;DR App

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

Written by gfrkad | Hacker
Published by HackerNoon on 2021/05/30