Menus and self deleting messages for the serenity discord framework
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trivernis 24ad0f54e4
Rename project to serenity-additions
Signed-off-by: trivernis <trivernis@protonmail.com>
3 years ago
src Rename project to serenity-additions 3 years ago
.gitignore Move content from 2b-rs subcrate 4 years ago
Cargo.lock Rename project to serenity-additions 3 years ago
Cargo.toml Rename project to serenity-additions 3 years ago
LICENSE Fix README 4 years ago
README.md Rename project to serenity-additions 3 years ago

README.md

Serenity Additions

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_additions::RegisterRichInteractions;

#[tokio::main]
async fn get_client {
    // stuff
    let client = Client::builder("TOKEN").register_serenity_additions().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_additions::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_additions::core::SHORT_TIMEOUT;
use serenity_additions::ephemeral_message::EphemeralMessage;
use serenity_additions::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