Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
B-2U opened this issue Aug 11, 2023 · 6 comments
Labels
documentation Who wants nice docs? Everyone! Who wants to write nice docs? Noone. just needs work There is nothing left to discuss or decide, someone just needs to do it (probably me at some point)

Comments

@B-2U
Copy link
Contributor

B-2U commented Aug 11, 2023

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
Copy link
Contributor Author

B-2U commented Aug 21, 2023

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

@kangalio
Copy link
Collaborator

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)

@B-2U
Copy link
Contributor Author

B-2U commented Aug 21, 2023

overwrite the action work pretty well, really appreciate!

@kangalio
Copy link
Collaborator

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 kangalio added the documentation Who wants nice docs? Everyone! Who wants to write nice docs? Noone. label Aug 31, 2023
@B-2U
Copy link
Contributor Author

B-2U commented Aug 31, 2023

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?

@kangalio kangalio added the just needs work There is nothing left to discuss or decide, someone just needs to do it (probably me at some point) label Aug 31, 2023
@kangalio
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Who wants nice docs? Everyone! Who wants to write nice docs? Noone. just needs work There is nothing left to discuss or decide, someone just needs to do it (probably me at some point)
Projects
None yet
Development

No branches or pull requests

2 participants