serenity-rs / poise

Discord bot command framework for serenity, with advanced features like edit tracking and flexible argument parsing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

autocomplete broke up when there's another command having same name using rename macro

B-2U opened this issue · comments

In my case, I want to make a command's prefix and slash seperately, like belowed

#[poise::command(slash_command, rename = "test")]
pub async fn test_slash(
    ctx: Context<'_>,
    #[autocomplete = "autocomplete_number11"]
    args: Option<u64>,
) -> Result<(), Error> {
    Ok(())
}

#[poise::command(prefix_command)]
pub async fn test(ctx: Context<'_>, #[rest] args: Option<Args>) -> Result<(), Error> {
    Ok(())
}

and the autocomplete wouldn't work, nor

#[poise::command(slash_command)]
pub async fn test(
    ctx: Context<'_>,
    #[autocomplete = "autocomplete_number11"]
    args: Option<u64>,
) -> Result<(), Error> {
    Ok(())
}

#[poise::command(prefix_command, rename = "test")]
pub async fn test_prefix(ctx: Context<'_>, #[rest] args: Option<Args>) -> Result<(), Error> {
    Ok(())
}

or is there a better way to do what I trying to do?

thank you so much

currently i renamed it "test-" temporally, really wish there's a better solution :(

To make the slash and prefix implementation of a single command different, you're supposed to overwrite the Command.slash_action or Command.prefix_action fields instead of having two wholly separate commands. An example can be seen in one of my bots:

https://github.com/kangalio/rustbot/blob/2632612d6b4c446c9454e9755ec31a9786aef8db/src/main.rs#L265-L273

However, I realize this is unintuitive, and documented nowhere whatsoever. Let's leave this issue open until documentation is better, or a more intuitive solution has been implemented (such as skipping commands with no autocomplete handler when dispatching an autocomplete event)

overwrite the action work pretty well, really appreciate!

Action plan should be:

  • document somewhere™ that you should make different command impls by defining the command signature twice and consolidating them into one by overwriting slash_action or prefix_action command fields (including example, where it would actually make sense to have differing impls, for example because the prefix impl has var args)
  • skip commands with no autocomplete handler when dispatching an autocomplete event

PRs open, or else I may or may not get around doing it myself eventually

for the first one, in order to have better way to document it, an idea I got is adding a some new method like poise::merge_command which take a 2 poise::Command, then overwrite those prefix only parameters (e.g. aliases, broadcast_typing etc)
do you think its a good idea?

I dislike how that obscures that "merging command" is just exchanging a single field. poise::Command { slash_action: slash_impl().slash_action, ..prefix_impl() } also makes clearer which of the two impls the other metadata is taken from