Prefix Commands Example¶
The examples/prefix_commands package demonstrates registration, aliases, help generation, and quoted argument parsing. Its source is available in the workspace at examples/prefix_commands/src/main.rs.
Command definition¶
use async_trait::async_trait;
use rustycord::message::ChannelMessage;
use rustycord::prefix::{PrefixCommand, PrefixCommandResult};
struct EchoCommand;
#[async_trait]
impl PrefixCommand for EchoCommand {
async fn execute(
&self,
_message: &ChannelMessage,
args: Vec<&str>,
) -> PrefixCommandResult {
Ok(Some(args.join(" ")))
}
fn description(&self) -> &str {
"Echo command arguments"
}
fn aliases(&self) -> Vec<&str> {
vec!["say", "repeat"]
}
}
Register it on a case-insensitive prefix:
```rust,no_run let listener = std::sync::Arc::new(PrefixListener::new("!")); listener.register_command("echo", Box::new(EchoCommand)).await;
// These forms are equivalent: // !echo hello // !say hello // !ECHO hello
## Quoted arguments
The `Args` parser preserves multi-word quoted values:
```text
!echo "hello world" 'quoted value'
For direct access to parsed arguments, override execute_with_args and use Args::get, Args::rest, or Args::parse_at.
Complete project¶
See examples/prefix_commands/src/main.rs for the full bot wiring, built-in help command, and command implementations.