Reading — step 1 of 5
Read
~1 min readCommands & Routing
Command Parsing
Bots typically respond to commands like !ping, /help, .kick @user.
Simple parser:
python
Discord slash commands /command arg:value:
- Structured. Defined ahead of time.
- Auto-completion in UI.
- Type-checked args.
- More effort to register than text commands.
Routing:
python
Argument parsing:
- Quoted strings: handle "with spaces".
- Type conversion:
!set delay 30→ int 30. - Optional / default args.
Modern: argparse-style declarations:
python
Help generation:
- Auto-generate from command metadata.
!helplists all commands.!help kickshows kick's args.
Subcommands:
!config get key,!config set key value.- Tree of routes.
Aliases:
!pingand!psame command.- Map all aliases to same handler.
Cooldowns:
- Prevent spam: each command has min interval per user.
- Track last-used per (user, command).
python
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…