Basic setup
Import and create a bot instance:Creating commands
Simple commands
Use the@bot.command() decorator to create commands:
!ping in either friend or party messages.
Commands with arguments
Commands can accept arguments:* in *, message means all remaining text becomes the message argument.
Command aliases
Add aliases for commands:!ping and !p work.
Command groups
Organize related commands into groups:!party, !party privacy public, !party kick Username
Checks
Restrict who can use commands:Custom checks
Create custom check functions:Cooldowns
Prevent command spam:Error handling
Handle command errors:Converters
Automatically convert arguments:Custom converters
Before and after hooks
Run code before or after commands:Context object
Thectx parameter provides useful information:
Best practices
Use meaningful command names
Use meaningful command names
Choose clear, descriptive names for your commands. Users should understand what a command does from its name.
Add help text
Add help text
Use docstrings to provide help text:Users can see this with
!help greet.Handle errors gracefully
Handle errors gracefully
Always implement error handling to provide helpful feedback when things go wrong.
Use type hints
Use type hints
Type hints enable automatic conversion and better error messages:
Next steps
Using cogs
Organize commands into modular cogs
Context reference
Learn about the Context object
Bot API reference
Full Bot class documentation
Command API reference
Detailed command documentation