serenity-rs / poise

Discord bot command framework for serenity, with advanced features like edit tracking and flexible argument parsing
MIT License
678 stars 117 forks source link

Please add documentation on how subcommands work #106

Closed dacid44 closed 2 years ago

dacid44 commented 2 years ago

It appears that subcommands (specifically for slash commands, using the command macro in my case) are somehow implemented, but the only times I can see them mentioned in the documentation (on the page for the command macro and the page for the Command struct, and not how to use them.

I can infer from compiler error messages that when specified in the command macro, subcommands should be the name of another function, and have worked out that:

Assuming these are accurate (which it's entirely possible that they're not), having these things shown in documentation, or even an example, would be great.

Or, is there a more idiomatic way to do this? Documenting that would also be really nice to have.

Here's my code that seems to work as expected:

#[poise::command(
    slash_command,
    subcommands("create"),
)]
async fn class(
    context: Context<'_>,
) -> Result<(), Error> {
    println!("parent command");
    Ok(())
}

#[poise::command(slash_command)]
async fn create(
    context: Context<'_>,
    text: String,
) -> Result<(), Error> {
    println!("test");
    Ok(())
}

Edit: I just found examples/framework_usage/commands/subcommand.rs. Still, a link to this example on the command macro doc page would be greatly appreciated, as well as links to the other similar examples by their relevant documentation. (You always seem to figure stuff out right after you ask for help, don't you?)

kangalio commented 2 years ago

https://kangalioo.github.io/poise/develop/poise/index.html#subcommands