Skip to main content

Crate autumn_plugin_discord

Crate autumn_plugin_discord 

Source
Expand description

autumn-plugin-discord: a Discord bot framework for Autumn.

Declare slash commands as data, mount the signed interactions webhook, and answer with typed responses:

ⓘ
use autumn_plugin_discord::{Command, DiscordPlugin, InteractionResponse, MessagePayload};
use autumn_web::prelude::*;

async fn ping(ctx: autumn_plugin_discord::CommandContext) -> AutumnResult<InteractionResponse> {
    Ok(InteractionResponse::channel_message(MessagePayload::content("Pong!")))
}

#[autumn_web::main]
async fn main() {
    autumn_web::app()
        .plugin(DiscordPlugin::new().command(Command::new("ping", "Replies with Pong!").handler(ping)))
        .run()
        .await;
}

§Configuration

[discord]
application_id = "123456789012345678"
public_key = "<64 hex chars from the developer portal>"

The bot token comes only from the DISCORD_BOT_TOKEN environment variable — never from the config file.

§Modules

ModulePurpose
configLayered [discord] config: file, env, builder overrides
commandsSlash-command declarations and dispatch
interactionsThe signed webhook route and the interactions::VerifiedInteraction extractor
verifyEd25519 signature verification
clientDiscord REST client (register commands, follow-ups)
gatewayMinimal gateway client (identify, heartbeat, dispatch)
healthGET /applications/@me readiness check
pluginThe plugin::DiscordPlugin

Re-exports§

pub use client::API_BASE;
pub use client::ApplicationInfo;
pub use client::DiscordClient;
pub use commands::Command;
pub use commands::CommandContext;
pub use commands::CommandHandler;
pub use commands::CommandRegistry;
pub use commands::IntoCommandHandler;
pub use config::DiscordConfig;
pub use error::Error;
pub use error::ErrorKind;
pub use error::Result;
pub use gateway::EventHandler;
pub use gateway::GATEWAY_URL;
pub use gateway::GatewayClient;
pub use health::DiscordHealth;
pub use health::indicator as health_indicator;
pub use interactions::VerifiedInteraction;
pub use plugin::DiscordPlugin;
pub use plugin::DiscordRuntime;
pub use types::ApplicationCommandData;
pub use types::CommandOption;
pub use types::CommandOptionType;
pub use types::CommandOptionValue;
pub use types::CommandRegistration;
pub use types::Interaction;
pub use types::InteractionResponse;
pub use types::InteractionResponseType;
pub use types::InteractionType;
pub use types::Member;
pub use types::MessagePayload;
pub use types::User;
pub use verify::SIGNATURE_HEADER;
pub use verify::TIMESTAMP_HEADER;
pub use verify::public_key_from_hex;
pub use verify::verify_interaction;

Modules§

client
Discord REST client.
commands
Slash-command declarations and dispatch.
config
Layered configuration for the Discord plugin.
error
Error types for the Discord plugin.
gateway
Minimal Discord gateway client.
health
Readiness check for the Discord plugin.
interactions
The Discord interactions webhook.
plugin
The Autumn plugin: DiscordPlugin and the shared DiscordRuntime.
types
Typed Discord payloads.
verify
Ed25519 signature verification for Discord interaction webhooks.