Skip to content
Command Parsing
step 1/5

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.
  • !help lists all commands.
  • !help kick shows kick's args.

Subcommands:

  • !config get key, !config set key value.
  • Tree of routes.

Aliases:

  • !ping and !p same 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…