poise
poise copied to clipboard
`context_menu_command` doesn't work for subcommands
The context_menu_command
macro arguments doesn't work with subcommands
Maybe I'm doing it wrong, but this is the code I have :
use crate::{Context, Error};
use poise::serenity_prelude as serenity;
/// Get the avatar of a user or the icon of the current server.
#[poise::command(slash_command, subcommands("user", "server"))]
pub async fn picture(_: Context<'_>) -> Result<(), Error> {
Ok(())
}
/// Get the icon of the current server.
#[poise::command(slash_command, guild_only)]
pub async fn server(ctx: Context<'_>) -> Result<(), Error> {
ctx.say(
ctx.guild()
.unwrap()
.icon_url()
.unwrap_or("🫥 This server doesn't have an icon.".to_string())
.replace("webp", "png?size=4096"),
)
.await?;
Ok(())
}
/// Get the avatar of a user.
#[poise::command(context_menu_command = "Get avatar", slash_command)]
pub async fn user(
ctx: Context<'_>,
#[description = "Discord profile to query information about"] user: serenity::User,
) -> Result<(), Error> {
let response = user.face().replace("webp?size=1024", "png?size=4096");
ctx.say(response).await?;
Ok(())
}
/picture user
and /picture server
work fine when invoking them via slash commands, but when I try to invoke Get avatar
, I get no reponse (timeout) and the function is never called (but is still registered as a context menu command!)
Thank you for the report
https://github.com/serenity-rs/poise/blob/5d02b8757d30e4588c193c5ba06e38806bbc1021/src/dispatch/slash.rs#L6-L32
I think the problem is here - subcommands are only traversed when the interaction has a subcommand too
And thank you for this really great crate!
So can I fix it in my code or do I have to wait for a release? I'd like to make a PR with a fix but I'm really unfamiliar to Rust macros...
This is a bug in poise, not your crate, but you can work around the bug by having two seperate functions for the slash version and the context menu version of your user / Get avatar command, where the context menu version is registered in poise as top-level, so that it doesn't hit this context menu subcommand bug
That's kind of what I have atm, I'll keep it that way for now, thank's anyway!