diff --git a/examples/generic_commands/main.rs b/examples/generic_commands/main.rs new file mode 100644 index 000000000000..8842eae8e938 --- /dev/null +++ b/examples/generic_commands/main.rs @@ -0,0 +1,23 @@ +//! If you need it, poise-annotated command functions can also be generic over the user data type +//! or error type +//! +//! The original use case for this feature was to have the same command in two different bots + +#[poise::command(slash_command)] +pub async fn example(ctx: poise::Context<'_, U, E>) -> Result<(), E> { + ctx.say(format!( + "My user data type is {} and the error type is {}", + std::any::type_name::(), + std::any::type_name::() + )) + .await + .unwrap(); + + Ok(()) +} + +#[tokio::main] +async fn main() { + let _example1 = example::<(), ()>(); + let _example2 = example::>(); +} diff --git a/macros/src/command/mod.rs b/macros/src/command/mod.rs index 9d6655f66325..079b00ea8b65 100644 --- a/macros/src/command/mod.rs +++ b/macros/src/command/mod.rs @@ -314,11 +314,12 @@ fn generate_command(mut inv: Invocation) -> Result ::poise::Command< + #function_visibility fn #function_name #function_generics() -> ::poise::Command< <#ctx_type_with_static as poise::_GetGenerics>::U, <#ctx_type_with_static as poise::_GetGenerics>::E, > {