#interaction #discord #serde #api

discordinteractions

A library to declare Discord Interactions easily in Rust, with support for Serde

2 stable releases

Uses old Rust 2015

1.0.1 May 18, 2023

#68 in #interaction

CC-BY-4.0

11KB
156 lines

Discord Interactions

A simple library for declaring Discord interactions.

Serde Support

Add the serde_support to your Cargo.toml to enable serde support.

discordinteractions = { version = "1", features = ["serde_support"] }

Example

DiscordInteraction {
    name: "test".to_string(),
    name_localizations: None,
    description: Some("test".to_string()),
    description_localizations: None,
    options: Some(vec![
        DiscordInteractionOption {
            name: "test".to_string(),
            description: "test".to_string(),
            autocomplete: Some(false),
            required: Some(true),
            channel_types: None,
            choices: None,
            max_length: None,
            min_length: None,
            max_value: None,
            min_value: None,
            description_localizations: None,
            name_localizations: None,
            option_type: command_creator::DiscordInteractionOptionType::String,
            options: None,
        }
    ]),
    default_member_permissions: None,
    dm_permission: None,
    default_permission: true,
    nsfw: false,
};

Using reqwest to send the interaction:

client.post("https://discord.com/api/v10/applications/{app.id}/commands")
    .header("User-Agent", "DiscordBot (url, version)")
    .header("Authorization", format!("Bot {}", BOT_TOKEN))
    .json(&declared_interaction).send();

Dependencies

~0–295KB