Build a Discord bot that automatically responds to commands typed by server members
Create a moderation bot that fires actions when events occur like a new user joining or a banned word appearing
Add a music bot to a Discord voice channel that can play audio on command
Voice support requires separately installing libsodium and opus system libraries before compiling the voice feature flag.
Serenity is a library written in Rust that lets developers build Discord bots. Discord is a chat platform popular with gaming communities, online groups, and software teams. A bot on Discord is an automated account that can respond to messages, react to events, play audio in voice channels, and more. Serenity handles the low-level work of connecting to Discord and leaves you to write the logic for what your bot should do. The library connects to Discord in two ways: through a persistent WebSocket connection called a gateway, which receives real-time events like new messages or users joining a channel, and through a REST API for sending messages, fetching data, and other actions. Serenity wraps both and provides a higher-level interface so developers do not have to manage the raw network details. It also maintains a local cache of Discord data like server membership and channel lists, so the bot can look things up without making a network request every time. Building a bot with Serenity follows a pattern of writing event handlers. You define what happens when a message arrives, when a user joins a voice channel, or when other Discord events fire. A basic ping-pong bot, which replies to a specific message, requires around 30 lines of Rust code as shown in the README example. The library also includes a command framework for handling bot commands that start with a prefix character, along with helpers for parsing arguments and running code before or after a command runs. The library is modular: features like caching, voice support, and the command framework can each be turned on or off in the project configuration file. Voice support requires additional system libraries (libsodium and opus) installed on the machine. Serenity requires Rust version 1.25 or newer. Documentation is available on docs.rs and example bots live in the examples folder of the repository.
← serenity-rs on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.