Skip to content

Commands

Commands are a structured way for users to interact with your bot. Instead of parsing on_message manually, you register named commands that the SDK matches and dispatches automatically.

@bot.command()
async def ping(ctx: syncopate.Context) -> None:
await ctx.reply("Pong!")

When a user types !ping, the bot calls your ping handler with a Context object.

class MyBot extends Bot {
@Command('ping')
async ping(ctx: Context) {
await ctx.reply('Pong!');
}
}

Arguments are automatically parsed from the message text:

@bot.command()
async def greet(ctx: syncopate.Context, name: str = "world") -> None:
await ctx.send(f"Hello, {name}!")
  • !greet → “Hello, world!”
  • !greet Alice → “Hello, Alice!”

Arguments are available through ctx.args:

@Command('greet')
async greet(ctx: Context) {
const name = ctx.args[0] ?? 'world';
await ctx.send(`Hello, ${name}!`);
}

By default, the command name matches the function name. Override it with the name parameter:

@bot.command(name="hi", description="Say hello")
async def greet_handler(ctx: syncopate.Context) -> None:
await ctx.reply("Hello!")
@Command('hi')
async greetHandler(ctx: Context) {
await ctx.reply('Hello!');
}

Every command handler receives a Context with these properties:

PropertyTypeDescription
messageMessageThe original message that triggered the command
channelChannelThe channel it was sent in
authorUserThe user who sent the command
commandstr / stringThe command name that was matched
argslist[str] / string[]Parsed arguments after the command name
MethodDescription
ctx.reply(content)Reply to the command message
ctx.send(content)Send a message to the same channel

The default prefix is !. Change it in the bot constructor:

bot = syncopate.Bot(token="...", command_prefix="/")
const bot = new MyBot({ token: '...', commandPrefix: '/' });