serenity-rich-interaction

Crates.ioserenity-rich-interaction
lib.rsserenity-rich-interaction
version0.3.1
sourcesrc
created_at2021-04-22 09:05:14.151788
updated_at2022-04-25 18:27:10.468979
descriptionMenus and self deleting messages for the serenity discord framework
homepage
repositoryhttps://github.com/Trivernis/serenity-rich-interactions
max_upload_size
id388040
size52,966
Julius Riegel (Trivernis)

documentation

README

Serenity Rich Interaction

This crate was renamed to serenity-additions to avoid confusions with discords interactions.

This crate provides some types for rich interactions with serenity such as Menus and Ephemeral (self deleting) Messages.

Usage

You have to register the module in the serenity client builder.

use serenity::client::Client;
use serenity_rich_interaction::RegisterRichInteractions;

#[tokio::main]
async fn get_client {
    // stuff
    let client = Client::builder("TOKEN").register_rich_interactions().await?;
    // stuff
}

Menu

use serenity::builder::CreateMessage;
use serenity::client::Context;
use serenity::model::id::ChannelId;
use serenity_rich_interaction::menu::{MenuBuilder, Page};
use std::time::Duration;
use serenity_rich_interaction::Result;

pub async fn create_menu(
    ctx: &Context,
    channel_id: ChannelId,
) -> Result<()> {
    let mut message1 = CreateMessage::default();
    message1.content("Hello");
    let mut message2 = CreateMessage::default();
    message2.content("World");
    
    MenuBuilder::new_paginator()
        .timeout(Duration::from_secs(120))
        .add_page(Page::new_static(message1))
        .add_page(Page::new_static(message2))
        .show_help()
        .build(ctx, channel_id)
        .await?;

    Ok(())
}

Ephemeral Message

use serenity_rich_interaction::core::SHORT_TIMEOUT;
use serenity_rich_interaction::ephemeral_message::EphemeralMessage;
use serenity_rich_interaction::Result;
use serenity::client::Context;
use serenity::model::id::ChannelId;

pub async fn create_ephemeral_message(ctx: &Context, channel_id: ChannelId) -> Result<()> {
    EphemeralMessage::create(&ctx.http, channel_id, SHORT_TIMEOUT, |m| {
        m.content("Hello World")
    }).await?;
    
    Ok(())
}

License

Apache-2.0

Commit count: 19

cargo fmt