Open-source project
twilight-rs/twilight avatar
twilight-rs/twilight

twilight: a crate ecosystem for the Discord API in Rust

Powerful, flexible, and scalable ecosystem of Rust libraries for the Discord API.

888 stars173 forksRustISC

At a glance

What is it?
Twilight splits the Discord API into a set of crates you choose between, from the type definitions in twilight-model to the gateway, the HTTP client and the in-memory cache, with a main twilight crate that does nothing at all on purpose. The design is a deliberate answer to how a library should track a platform that changes underneath you, and the price is that you assemble the pieces yourself.
Who is it for?
Adopt twilight if you are writing a Discord bot or integration in Rust and want typed models, a gateway that handles sharding, and an HTTP client that already understands Discord's rate limits. Do not adopt it if you want a single crate that does everything, because the main twilight crate is deliberately empty and you assemble the parts yourself.
Can I use it commercially?
Yes. ISC is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 3 days ago.
What is it written in?
Mainly Rust, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on October 24, 2026, and from our analysis. They are not legal advice.

Editorial analysis

The problem: a platform that changes and a bot that has to keep up

The Discord API is a large surface of models, a stateful WebSocket gateway, a REST API with per-route rate limits, and a set of behavioural rules that shift as the platform changes. Any one bot has to deal with all of it, and the parts are only useful together.

Twilight is a powerful, flexible and scalable ecosystem of Rust libraries for the Discord API, and the word ecosystem is the accurate one. The repository is a Cargo workspace with a member per concern, and the project describes itself as an ecosystem of first-class crates including twilight-cache-inmemory, twilight-gateway, twilight-http, twilight-model and more.

The audience is Rust developers building Discord bots, integrations and tooling, and the appeal is that the pieces are separated along the lines of the problem rather than along the lines of a monolith. You take the types, or you take the types plus the gateway, or you take everything, and the crates that you do not use cost you nothing in compile time.

The licence is ISC for all first-party crates, with the logo separately licensed CC BY-SA 4.0 and credited to Fezhoof. The default branch is main, the last push was on 2026-10-19, and the published releases are twilight-0.17.1 from 2025-12-13, twilight-0.17.0 from 2025-11-08 and twilight-validate-0.16.0 from 2025-01-12.

The advertisement crate, and why the split is the design

The most surprising thing about the project is stated plainly and early: the main twilight crate is purely an advertisement crate, it has no functionality, and you should use the individual crates listed below instead.

That is a deliberate choice, and it is the one that makes the rest of the ecosystem work. The workspace manifest lists the members, and each of the twelve is a separate crate with its own version and its own release. The umbrella crate exists so that the project is discoverable, and so that the documentation has a landing page, and nothing more.

The recommendation is that most users start with four crates:

- twilight-cache-inmemory - twilight-gateway - twilight-http - twilight-model

And the guidance for anything else is that if you need other functionality Twilight provides, you can just add that dependency in.

The result is a dependency graph you control. A tool that only needs to send a REST request depends on twilight-http and twilight-model and nothing else, while a full bot adds the gateway and the cache. For a library that tracks a platform whose model definitions change often, that separation is what makes it possible to upgrade one part without dragging the others along.

twilight-model: the type surface, and why it is split by sub-module

twilight-model holds the models defining structures, enums and bitflags for the entirety of the Discord API. It is split into sub-modules, with gateway containing the WebSocket gateway types, guild containing types owned by guilds, which the documentation calls servers, voice containing the types used by the Voice WebSocket API, and more.

The reason for that split is stated as a use case rather than a preference: all of this is in a single crate so that you can use gateway models without depending on twilight-gateway, and one use case is if you write your own WebSocket gateway implementation.

That is a design decision that most users will not exercise and that a library of this kind gets right anyway. The alternative, splitting the models into a dozen crates, would multiply the dependency list of every project for a benefit almost nobody needs. Keeping the models in one crate while keeping the implementations in separate crates gives you the dependency hygiene where it matters and the convenience where it does not.

The types are also where the volume of the Discord API shows up. Every structure, every enum, every bitflag the platform exposes is a Rust type here, and it is the crate that has to be regenerated when the platform adds a field. The repository even carries a model-webhook-slash.rs example, which is a small reminder that the model crate covers the whole surface rather than the subset a typical bot touches.

gateway, http and the cache: the three you will actually use

twilight-gateway implements Discord's sharding gateway sessions, and is responsible for receiving stateful events in real time from Discord and sending some stateful information.

twilight-http is the HTTP client supporting all of the Discord REST API. It is based on hyper, it meets Discord's ratelimiting requirements, and it supports proxying. That last combination is why the crate exists rather than you composing hyper calls yourself: the rate limit handling is not a header you can ignore, because the limit is per route and per bucket, and a naive client will get itself rate limited in a way that is hard to diagnose.

There is also a separate crate, twilight-http-ratelimiting, in the workspace, and the gateway has its own companion, twilight-gateway-queue, described as a trait and some implementations that are used by the gateway to ratelimit identify calls, with the note that developers should prefer to use the re-exports of these crates through the gateway. Identify calls are the gateway's request to Discord to tell it which members and online status it wants, and they are the part of the protocol that most needs queuing rather than naive concurrency.

twilight-cache-inmemory is the in-process memory based cache over objects received from the gateway, responsible for holding and managing information about things like guilds, channels, role information, voice states, and any other events that come from Discord. The word in-process is the constraint to note: a cache that lives inside one process is fast and simple, and it is shared by nothing, so a bot that runs several processes does not have a shared view.

There is an example directory called cache-optimization, which suggests the performance of that cache is a live concern rather than a solved one.

The supporting crates: standby, lavalink, mention, util and validate

The crates outside the core set are officially supported but are described as vendor-specific or non-essential for most users, and they cover the awkward parts of writing a bot.

twilight-standby is an event processor that allows tasks to wait for an event to come in. The example given is a reaction menu where you want to wait for a specific reaction to arrive, which is the kind of problem that otherwise turns into a tangle of channels and message handlers.

twilight-lavalink is the client for Lavalink, the audio player, and it includes support for managing multiple nodes, a player manager for conveniently using players to send events and retrieve information for each guild, and an HTTP module for creating requests using the http crate and providing models to deserialize their responses.

twilight-mention creates display formatters for various model types that format mentions, for example formatters for mentioning a channel or emoji, or pinging a role or user. That is a small crate that removes a class of small bugs, because mention syntax is exactly the sort of thing that has to be right every time and is easy to get wrong by hand.

twilight-util holds utilities that do not fit in any other crate, and currently contains a trait to make extracting data from Discord identifiers, the Snowflakes, easier, and a calculator to calculate the permissions of a member in a guild or channel. The permission calculator in particular is the kind of thing that is easy to get subtly wrong and impossible to test by eye.

And twilight-validate, whose release appears in the repository's published versions, is the crate for validating events and payloads against the API's expectations, which is what you want in a service that accepts Discord interactions from outside.

Getting started: the template, and the MSRV caveat

The quick start is two commands, and they use a template repository rather than a generator built into the library.

First, install cargo-generate:

bash
cargo install cargo-generate

Then create a bot based upon the template:

bash
cargo generate twilight-rs/template

The template lives in a separate repository, twilight-rs/template, which is a sensible arrangement: the ecosystem ships libraries, and the skeleton of an application ships with it.

The version policy is the one thing to read before you pin anything. Twilight supports a MSRV of Rust 1.89, and the project states that they do not consider changes to the MSRV semver-incompatible, therefore it may change in minor or patch releases. That is unusual and important: a patch upgrade can raise the compiler floor your team has to meet, and a Cargo.lock that worked yesterday can stop building today.

The documentation and the repository are in reasonable shape for a project of this size, with a book/ directory behind the twilight.rs site, an examples/ directory with a Cargo.toml and a set of runnable programs, and the supporting configuration for a real project: nextest.toml for the test runner, clippy.toml, .rustfmt.toml, .codespellrc, .codecov.yml, a CODE_OF_CONDUCT.md, and a CONTRIBUTING_AI_POLICY.md that sets the rules for automated contributions. The release tooling is visible too, with release.sh, release.toml, cliff.toml and gen-changelogs.sh.

Licence, maintenance and where twilight is the wrong tool

The licence is ISC for all first-party crates, with the licence text in LICENSE.md at the root of the repository, and the logo is separately licensed under CC BY-SA 4.0. ISC is a short permissive licence, so there is nothing to negotiate before you put a twilight based bot into a product.

The maintenance picture is good. The repository is not archived, the last push was on 2026-10-19, and the 0.17 line shipped in November and December 2025 with the validate crate released earlier in 2025. For a library whose job is to track a platform that changes, having a maintained workspace of twelve crates is the point.

Where twilight is the wrong tool is mostly about scope and about the Rust choice. If you want one dependency that gives you a bot, this is not it, because the umbrella crate is empty by design and you assemble the pieces. If you are not writing Rust, the ecosystem is of no use, and the Discord API itself has first party libraries in other languages. If your bot needs a feature the model crate has not caught up with, you are waiting on a release.

The one design consequence to plan for is the MSRV policy. A project that treats its compiler floor as non-breaking means you cannot assume that a minor or patch upgrade is safe for your toolchain, so pin the crates, read the changelog when you upgrade, and if your build environment is fixed, take the version floor into account when you plan an update cycle. Everything else about the design is a direct answer to the problem it set out to solve.

Editorial conclusion

Adopt twilight if you are writing a Discord bot or integration in Rust and want typed models, a gateway that handles sharding, and an HTTP client that already understands Discord's rate limits. Do not adopt it if you want a single crate that does everything, because the main twilight crate is deliberately empty and you assemble the parts yourself. Before you start, read the MSRV policy, since the project states that changes to the minimum supported Rust version are not treated as semver incompatible and may land in a minor or patch release, and check the twilight-validate crate if you need to validate inbound events against the API's schema.

Frequently asked questions

What is the twilight crate and why does it have no functionality?

It is purely an advertisement crate, with no functionality of its own, and the documentation asks you to use the individual crates instead. The real library is a Cargo workspace of about a dozen member crates, of which the main ones are twilight-model, twilight-http, twilight-gateway and twilight-cache-inmemory.

Which twilight crates do most users need?

The project recommends starting with twilight-cache-inmemory, twilight-gateway, twilight-http and twilight-model, and adding any other crate Twilight provides only if you need it. The workspace also contains twilight-http-ratelimiting, twilight-gateway-queue, twilight-standby, twilight-lavalink, twilight-mention, twilight-util and twilight-validate.

How does twilight handle Discord's rate limits?

The HTTP client is based on hyper, meets Discord's ratelimiting requirements and supports proxying, and there is a separate twilight-http-ratelimiting crate in the workspace. On the gateway side, twilight-gateway-queue is a trait and some implementations used by the gateway to ratelimit identify calls, and developers are asked to prefer the re-exports through the gateway.

What is the minimum supported Rust version for twilight, and can it change?

Twilight supports a MSRV of Rust 1.89, and the project states that changes to the MSRV are not considered semver-incompatible, so the floor may rise in a minor or patch release. Pin the crates and read the changelog when upgrading.

How do I start a new bot with twilight?

Install cargo-generate with cargo install cargo-generate, then run cargo generate twilight-rs/template to create a bot based upon the template, which lives in a separate twilight-rs/template repository. The ecosystem also ships runnable examples for gateway, http, lavalink and model usage.

Official sources

  1. License: ISC
  2. Project website
  3. README
  4. Releases
  5. twilight-rs/twilight on GitHub
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/twilight-rs-twilight.svg)](https://hysenlabs.com/projects/twilight-rs-twilight)

Was this useful?