๐ŸŽฎInstall KODO โ€” Learn Discord.py offline
0% Complete
Part 2
Module 1 of 30

Getting Started with Discord.py

Set up your development environment, create a Discord application, and get your bot token.

๐Ÿ New to Python? Don't know Python basics yet? Learn it first at KODO Python Mastery โ†’ before diving into Discord.py. You'll need to understand variables, functions, and async/await.

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!

BASH
pip install discord.py python -c "import discord; print(discord.__version__)"

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:

Module 2 of 30

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.

PYTHON
import discord from discord.ext import commands intents = discord.Intents.default() intents.message_content = True bot = commands.Bot(command_prefix="!", intents=intents) @bot.event async def on_ready(): print(f"Logged in as {bot.user}") @bot.command() async def ping(ctx): await ctx.send(f"Pong! {round(bot.latency*1000)}ms") bot.run("YOUR_TOKEN")
Never hardcode your token! Use environment variables or a .env file.

Q1: What decorator is used for commands?

Q2: What does bot.latency measure?

Module 3 of 30

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.

PYTHON
@bot.command(aliases=["hi"]) async def hello(ctx): await ctx.send(f"Hello {ctx.author.mention}!")

Q1: What does ctx.author return?

Module 4 of 30

Command Parameters

Accept typed user input.

PYTHON
@bot.command() async def greet(ctx, member: discord.Member): await ctx.send(f"Hello {member.mention}!")
Module 5 of 30

Events Deep Dive

React to everything in your server.

PYTHON
@bot.event async def on_member_join(member): await member.guild.system_channel.send(f"Welcome {member.mention}!")
Module 6 of 30

Embeds

Create rich messages with Discord Embeds.

PYTHON
embed = discord.Embed(title="Server Info", color=0x5865F2) embed.add_field(name="Members", value="100") await ctx.send(embed=embed)
Module 7 of 30

Cogs Basics

Organize your bot professionally.

PYTHON
class Greetings(commands.Cog): def __init__(self, bot): self.bot = bot @commands.command() async def hello(self, ctx): await ctx.send("Hi!") async def setup(bot): await bot.add_cog(Greetings(bot))
Module 8 of 30

Error Handling

Gracefully handle errors.

PYTHON
@bot.event async def on_command_error(ctx, error): if isinstance(error, commands.MissingPermissions): await ctx.send("No permission!")
Module 9 of 30

Permissions System

Control who uses commands.

PYTHON
@bot.command() @commands.has_permissions(kick_members=True) async def kick(ctx, member: discord.Member): await member.kick() await ctx.send(f"Kicked {member.name}")
Module 10 of 30

Practice Project 1

Build an Info Bot using Modules 1-9.

Requirements

Build: !serverinfo, !userinfo, !ping, !avatar, welcome messages, error handling. Use cogs.

Continue to Part 2 โ†’
Kodo Agent
๐Ÿค–
Hello! I'm Kodo Agent.
I know everything about this Discord.py course โ€” all 30 modules. Ask me about commands, cogs, embeds, moderation, music bots, or anything else!