Skip to content

Commands

Declare commands in plugin-info.commands. When the user runs one, the plugin receives event.command.

commands: vec![Command {
name: "roll".into(),
description: "Roll a die".into(),
options: vec![CommandOption {
name: "sides".into(),
description: "Number of sides".into(),
kind: CommandOptionKind::Integer,
required: false,
choices: Vec::new(),
}],
}],
fn on_event(&mut self, event: Event) {
let Event::Command(invocation) = event else {
return;
};
let sides = invocation
.arguments
.iter()
.find_map(|argument| match argument.value {
CommandValue::Integer(sides) if argument.name == "sides" => Some(sides),
_ => None,
})
.unwrap_or(6);
actions::send_local_message(invocation.channel_id, &format!("Rolling a d{sides}"));
}

actions::send_local_message shows a message only the current user can see. Use actions::send_message to send a real message.

Commands should do something a bot cannot. Simple commands like /cat belong in a user-installable Discord app; see the plugin rules.