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
| Module | Purpose |
|---|---|
config | Layered [discord] config: file, env, builder overrides |
commands | Slash-command declarations and dispatch |
interactions | The signed webhook route and the interactions::VerifiedInteraction extractor |
verify | Ed25519 signature verification |
client | Discord REST client (register commands, follow-ups) |
gateway | Minimal gateway client (identify, heartbeat, dispatch) |
health | GET /applications/@me readiness check |
plugin | The 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:
DiscordPluginand the sharedDiscordRuntime. - types
- Typed Discord payloads.
- verify
- Ed25519 signature verification for Discord interaction webhooks.