Crates.io | serenity-additions |
lib.rs | serenity-additions |
version | 0.3.4 |
source | src |
created_at | 2022-04-25 18:23:19.390527 |
updated_at | 2022-10-15 14:16:06.213958 |
description | Menus and self deleting messages for the serenity discord framework |
homepage | |
repository | https://github.com/Trivernis/serenity-rich-interactions |
max_upload_size | |
id | 574038 |
size | 53,372 |
This crate provides some types for rich interactions with serenity such as Menus and Ephemeral (self deleting) Messages.
You have to register the module in the serenity client builder.
use serenity::client::Client;
use serenity_additions::RegisterRichInteractions;
use serenity::prelude::GatewayIntents;
let client = Client::builder("TOKEN", GatewayIntends::default()).register_serenity_additions()
use serenity::builder::CreateMessage;
use serenity::client::Context;
use serenity::model::id::ChannelId;
use serenity_additions::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(())
}
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(())
}
Apache-2.0