A simple Discord bot built with Python and discord.py library.
- Hello Command: Greets users with a friendly message
- Ping Command: Shows bot latency
- Info Command: Displays server information in an embed
- Echo Command: Repeats user messages
- Clear Command: Deletes specified number of messages (requires permissions)
- Go to the Discord Developer Portal
- Click "New Application" and give it a name
- Go to the "Bot" section and click "Add Bot"
- Copy the bot token (you'll need this later)
- Go to "OAuth2" → "URL Generator"
- Select "bot" under scopes
- Select the permissions you want (at minimum: Send Messages, Read Message History, Use Slash Commands)
- Use the generated URL to invite your bot to your server
pip install -r requirements.txt- Create a
.envfile in the project root - Add your bot token:
DISCORD_TOKEN=your_actual_bot_token_here
python bot.py!hello- Greets the user!ping- Shows bot latency!info- Displays server information!echo <message>- Repeats the message!clear [amount]- Deletes messages (default: 5, max: 100)!help- Shows all available commands
discord-bot/
├── bot.py # Main bot code
├── requirements.txt # Python dependencies
├── env_example.txt # Example environment variables
└── README.md # This file
You can easily add new commands by creating new functions with the @bot.command() decorator. For example:
@bot.command(name='custom')
async def custom_command(ctx):
await ctx.send("This is a custom command!")- Bot not responding: Make sure the bot has the correct permissions in your server
- Token error: Verify your bot token is correct in the
.envfile - Permission errors: Ensure the bot has the necessary permissions for the commands you're trying to use
- Never share your bot token publicly
- Keep your
.envfile in your.gitignore - Regularly rotate your bot token if compromised