Ever wanted your own Discord bot but didn’t know where to start? With Python, it’s easier than you think—even if you’re totally new to coding. In this guide, I’ll show you step by step how to create a simple bot for your server. Let’s get started!
For this example we will create a discord bot to send us alerts every time a Boss is about to spawn in a game called Pixel Heroes that runs on the Ronin Chain.
To get started with this bot, you'll need:
Python 3.11: Ensure you have Python 3.11 installed, as it's the best compatible version with discord.py.
Discord Developer Mode: Make sure to toggle the developer mode as shown in the image.
Discord Developer Portal:Go to https://discord.com/developers/applications
- Click on New Application
Discord Bot Token: To get your Bot Token you have to click on Bot and after click on Reset Token, this will give you a ned Token !!!IMPORTANT DON’T SHARE THIS TOKEN!!!.
Scroll down to Bot Permissions, and for this example we are only going to check Send Messages in Text Permission
Discord Server: Create your channer for the bot testing
- Right click on the channel to get the Channel ID
Once you have all the information listed before you go to the repository github.com/VahagnCh/DiscordBot
Setup Instructions:
Clone the Repository: Download the code from the repository to your local machine.
Install Dependencies: Use
pip
to install the required packages, primarilydiscord.py
.Configure Environment Variables: Rename
.env.example
to.env
and input your Discord bot token.- It is important to NOT hardcode your token and use .env file, or for extra security your can encrypt it.
Run the Bot: Execute
bot.py
to start the bot.- You can edit, update or change totally the cody for your needs and preferences.
And if you want to start from zero I would recommend following the Quickstark guide from discord.py documentation.
# This example requires the 'message_content' intent.
import discord
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f'We have logged in as {client.user}')
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$hello'):
await message.channel.send('Hello!')
client.run('your token here')
Documentation you might need: