[][src]Struct serenity_utils::menu::Menu

pub struct Menu<'a> {
    pub ctx: &'a Context,
    pub msg: &'a Message,
    pub pages: &'a [CreateMessage<'a>],
    pub options: MenuOptions,
}

A fully functioning reaction-based menu.

A reaction menu is a paginated message where the user can use reactions to change the page/content of the message.

Example

use serenity_utils::{
    menu::{Menu, MenuOptions},
    Error
};

async fn use_menu(ctx: &Context, msg: &Message) -> Result<(), Error> {
    let mut message_one = CreateMessage::default();
    message_one
        .content("Page number one!")
        .embed(|e| {
            e.description("The first page!");

            e
        });

    let mut message_two = CreateMessage::default();
    message_two
        .content("Page number two!")
        .embed(|e| {
            e.description("The second page!");

            e
        });

    let pages = [message_one, message_two];

    // Creates a new menu.
    let menu = Menu::new(ctx, msg, &pages, MenuOptions::default());

    // Runs the menu and returns optional `Message` used to display the menu.
    let opt_message = menu.run().await?;

    Ok(())
}

A reaction menu can be configured by changing its options. See MenuOptions for more details.

Fields

ctx: &'a Context

The Discord/serenity context.

msg: &'a Message

The invocation message.

pages: &'a [CreateMessage<'a>]

The pages of the menu.

options: MenuOptions

The menu options.

Implementations

impl<'a> Menu<'a>[src]

pub fn new(
    ctx: &'a Context,
    msg: &'a Message,
    pages: &'a [CreateMessage<'a>],
    options: MenuOptions
) -> Self
[src]

Creates a new Menu object.

pub async fn run(self) -> Result<Option<Message>, Error>[src]

Runs the reaction menu.

It returns the message used to display the reaction menu after running.

Errors

Returns Error::SerenityError if

  • current user/bot doesn't have the permissions to add reactions
  • msg is specified in MenuOptions but the current user/bot isn't the author of the message
  • the message content lengths are over Discord's limit
  • current user/bot doesn't have the permissions to send an message/embed

Returns Error::InvalidChoice if the user selects an invalid choice, ie, reacts to an emoji that does not correspond to any control.

Returns Error::Other if

  • pages is empty
  • the page number specified in MenuOptions is out of bounds

Auto Trait Implementations

impl<'a> !RefUnwindSafe for Menu<'a>

impl<'a> Send for Menu<'a>

impl<'a> Sync for Menu<'a>

impl<'a> Unpin for Menu<'a>

impl<'a> !UnwindSafe for Menu<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> WithSubscriber for T[src]