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