Type Definition serenity_utils::menu::ControlFunction
source · [−]pub type ControlFunction = Arc<dyn for<'b> Fn(&'b mut Menu<'_>, Reaction) -> Pin<Box<dyn Future<Output = ()> + Send + 'b>> + Sync + Send>;
Expand description
A function used to control the behaviour of a reaction menu’s reaction.
An example implementation is provided here:
use serenity::model::channel::Reaction;
use serenity_utils::menu::Menu;
async fn first_page<'a>(menu: &mut Menu<'a>, reaction: Reaction) {
// Remove the reaction used to change the menu.
let _ = &reaction.delete(&menu.ctx.http).await;
// Set page number to `0`.
menu.options.page = 0;
}
Please note that the above function is not a ControlFunction
. To make it
a control function, you need to pin it and then create an Arc
of it.
use std::sync::Arc;
let control_function = Arc::new(|m, r| Box::pin(first_page(m, r)));
Now, control_function
can be used to control a menu.