Getting Started with Discord.py
Set up your development environment, create a Discord application, and get your bot token.
What is Discord.py?
Discord.py is a modern, feature-rich Python library for interacting with Discord's API. It allows you to create bots that can send messages, moderate servers, play music, and much more. It's the most popular Python wrapper for Discord, with over 12,000 stars on GitHub.
Prerequisites
- Python 3.8 or higher installed
- A Discord account
- A text editor (VS Code recommended)
- Basic Python knowledge (variables, functions, async/await)
- Terminal/Command Prompt access
Step 1: Create a Discord Application
Go to the Discord Developer Portal, click "New Application", give it a name, and create it.
Step 2: Get Your Bot Token
In your application, go to the Bot tab, click "Add Bot", then "Reset Token". Never share this token!
Step 3: Invite Your Bot
Go to OAuth2 โ URL Generator, select bot and applications.commands, choose Administrator, and open the URL.
Knowledge Check โ Module 1 (Q1)
Where do you create a Discord bot application?
Knowledge Check โ Module 1 (Q2)
Your bot token should be:
Your First Discord Bot
Write your first bot, understand the basic structure, and get it online.
Bot Structure Overview
Every Discord.py bot: create Bot instance โ define events โ define commands โ run with token.
.env file.Q1: What decorator is used for commands?
Q2: What does bot.latency measure?
Commands System
Master @bot.command(), parameters, and the ctx object.
The ctx Object
ctx.author, ctx.guild, ctx.channel, ctx.message โ context of every command.
Q1: What does ctx.author return?
Command Parameters
Accept typed user input.
Events Deep Dive
React to everything in your server.
Embeds
Create rich messages with Discord Embeds.
Cogs Basics
Organize your bot professionally.
Error Handling
Gracefully handle errors.
Permissions System
Control who uses commands.
Practice Project 1
Build an Info Bot using Modules 1-9.
Requirements
Build: !serverinfo, !userinfo, !ping, !avatar, welcome messages, error handling. Use cogs.