poise icon indicating copy to clipboard operation
poise copied to clipboard

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

Open B-2U opened this issue 1 year ago • 6 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

B-2U avatar Aug 11 '23 17:08 B-2U

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

B-2U avatar Aug 21 '23 11:08 B-2U

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)

kangalio avatar Aug 21 '23 11:08 kangalio

overwrite the action work pretty well, really appreciate!

B-2U avatar Aug 21 '23 18:08 B-2U

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

kangalio avatar Aug 31 '23 00:08 kangalio

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?

B-2U avatar Aug 31 '23 00:08 B-2U

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

kangalio avatar Aug 31 '23 01:08 kangalio