Apr 2, 2024 | Development
In this tutorial, we’ll walk through the process of creating a Discord bot using Python. Discord is a popular platform for gamers and communities to communicate, and creating a bot can enhance your server’s functionality in various ways.
Before we begin, ensure you have the following installed:
You’ll also need a Discord account and permissions to create a bot and add it to a server.
Set Up a Discord Application
Get Your Bot’s Token
Install Discord.py
pip install discord.py
# bot.py
import discord
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as {0.user}'.format(client))
@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_BOT_TOKEN_HERE')
Replace ‘YOUR_BOT_TOKEN_HERE’ with the token you copied earlier.
python bot.py
Your bot should now be online and responding to commands in your Discord server!