{"id":13410938,"url":"https://github.com/twilight-rs/twilight","last_synced_at":"2025-05-13T20:09:56.469Z","repository":{"id":36987211,"uuid":"205719706","full_name":"twilight-rs/twilight","owner":"twilight-rs","description":"Powerful, flexible, and scalable ecosystem of Rust libraries for the Discord API.","archived":false,"fork":false,"pushed_at":"2025-04-15T08:03:24.000Z","size":11501,"stargazers_count":730,"open_issues_count":60,"forks_count":137,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-04-23T07:27:35.596Z","etag":null,"topics":["discord","discord-api","discord-bot","rust","twilight-rs"],"latest_commit_sha":null,"homepage":"https://discord.gg/twilight-rs","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twilight-rs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"open_collective":"twilight"}},"created_at":"2019-09-01T18:59:16.000Z","updated_at":"2025-04-22T22:46:58.000Z","dependencies_parsed_at":"2024-01-01T05:34:44.415Z","dependency_job_id":"67a7ed8b-ac43-4948-bacd-c8f8e857f56e","html_url":"https://github.com/twilight-rs/twilight","commit_stats":{"total_commits":2351,"total_committers":92,"mean_commits":"25.554347826086957","dds":0.7269247128881327,"last_synced_commit":"08ed124a201e24fda6e130100465d94b1ea7a877"},"previous_names":[],"tags_count":617,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twilight-rs%2Ftwilight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twilight-rs%2Ftwilight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twilight-rs%2Ftwilight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twilight-rs%2Ftwilight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twilight-rs","download_url":"https://codeload.github.com/twilight-rs/twilight/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251175802,"owners_count":21547732,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["discord","discord-api","discord-bot","rust","twilight-rs"],"created_at":"2024-07-30T20:01:10.346Z","updated_at":"2025-04-28T10:48:24.857Z","avatar_url":"https://github.com/twilight-rs.png","language":"Rust","funding_links":["https://opencollective.com/twilight"],"categories":["API Libraries","Rust","Libraries"],"sub_categories":["Rust"],"readme":"# twilight\n\n[![codecov badge][]][codecov link] [![discord badge][]][discord link] [![github badge][]][github link] [![license badge][]][license link] ![rust badge]\n\n![project logo][logo]\n\n`twilight` is a powerful, flexible, and scalable ecosystem of Rust libraries\nfor the Discord API.\n\nThe ecosystem of first-class crates includes [`twilight-cache-inmemory`],\n[`twilight-gateway`], [`twilight-http`], [`twilight-model`], and more. These\nare explained in detail below.\n\nThe main `twilight` crate is purely an advertisement crate: it has *no*\nfunctionality. Please use the individual crates listed below instead!\n\n## Installation\n\nTwilight supports a MSRV of Rust 1.79. We do not consider changes to the MSRV\nsemver-incompatible, therefore it may change in minor or patch releases.\n\nWe recommend that most users start out with these crates:\n\n- [`twilight-cache-inmemory`][crates:cache-inmemory]\n- [`twilight-gateway`][crates:gateway]\n- [`twilight-http`][crates:http]\n- [`twilight-model`][crates:model]\n\nIf you need any other functionality that Twilight provides, you can just add\nthat dependency in.\n\n## Core Crates\n\nThese are essential crates that most users will use together for a full\ndevelopment experience. You may not need all of these - such as\n[`twilight-cache-inmemory`] - but they are often used together to accomplish\nmost of what you need.\n\n### [`twilight-model`]\n\nModels defining structures, enums, and bitflags for the entirety of the\nDiscord API. It is split into a number of sub-modules, such as `gateway` for\ncontaining the WebSocket gateway types, `guild` for containing types owned\nby guilds (servers), `voice` containing the types used by the Voice\nWebSocket API, and more.\n\nThese are all in a single crate so that you can use `gateway` models without\ndepending on [`twilight-gateway`]. One use case is if you write your own\nWebSocket gateway implementation.\n\n### [`twilight-cache-inmemory`]\n\nIn-process-memory based cache over objects received from the gateway. It's\nresponsible for holding and managing information about things like guilds,\nchannels, role information, voice states, and any other events that come\nfrom Discord.\n\n### [`twilight-gateway`]\n\nImplementation of Discord's sharding gateway sessions. This is responsible\nfor receiving stateful events in real-time from Discord and sending *some*\nstateful information.\n\n### [`twilight-http`]\n\nHTTP client supporting all of the Discord REST API. It is based on `hyper`.\nIt meets Discord's ratelimiting requirements and supports proxying.\n\n### [`twilight-standby`]\n\nEvent processor that allows for tasks to wait for an event to come in. This\nis useful, for example, when you have a reaction menu and want to wait for a\nspecific reaction on it to come in.\n\n## Additional Crates\n\nThese are crates that are officially supported by Twilight, but aren't\nconsidered core crates due to being vendor-specific or non-essential for\nmost users.\n\n### [`twilight-lavalink`]\n\nClient for [Lavalink] as part of the twilight ecosystem.\n\nIt includes support for managing multiple nodes, a player manager for\nconveniently using players to send events and retrieve information for each\nguild, and an HTTP module for creating requests using the [`http`] crate and\nproviding models to deserialize their responses.\n\n### [`twilight-mention`]\n\nCreate display formatters for various model types that format mentions. For\nexample, it can create formatters for mentioning a channel or emoji, or\npinging a role or user.\n\n### [`twilight-util`]\n\nUtility crate that adds utilities to the twilight ecosystem that do not fit\nin any other crate. Currently, it contains:\n\n- A trait to make extracting data from Discord identifiers (Snowflakes)\n  easier;\n- A calculator to calculate the permissions of a member in a guild or\n  channel.\n\n### [`twilight-gateway-queue`]\n\nA trait and some implementations that are used by the gateway to ratelimit\nidentify calls. Developers should prefer to use the re-exports of these\ncrates through the gateway.\n\n## Examples\n\nThe following example is a template for bootstrapping a new bot using\nTwilight's HTTP and gateway clients with its in-memory cache. In order to\nrun this, replace the contents of a new project's `main.rs` file with the\nfollowing. Be sure to set the `DISCORD_TOKEN` environment variable to your\nbot's token. You must also depend on `tokio`, `twilight-cache-inmemory`,\n`twilight-gateway`, `twilight-http`, and `twilight-model` in your `Cargo.toml`.\n\n```rust,no_run\nuse std::{env, error::Error, sync::Arc};\nuse twilight_cache_inmemory::{DefaultInMemoryCache, ResourceType};\nuse twilight_gateway::{Event, EventTypeFlags, Intents, Shard, ShardId, StreamExt as _};\nuse twilight_http::Client as HttpClient;\n\n#[tokio::main]\nasync fn main() -\u003e anyhow::Result\u003c()\u003e {\n    // Initialize the tracing subscriber.\n    tracing_subscriber::fmt::init();\n\n    let token = env::var(\"DISCORD_TOKEN\")?;\n\n    // Use intents to only receive guild message events.\n    let mut shard = Shard::new(\n        ShardId::ONE,\n        token.clone(),\n        Intents::GUILD_MESSAGES | Intents::MESSAGE_CONTENT,\n    );\n\n    // HTTP is separate from the gateway, so create a new client.\n    let http = Arc::new(HttpClient::new(token));\n\n    // Since we only care about new messages, make the cache only\n    // cache new messages.\n    let cache = DefaultInMemoryCache::builder()\n        .resource_types(ResourceType::MESSAGE)\n        .build();\n\n    // Process each event as they come in.\n    while let Some(item) = shard.next_event(EventTypeFlags::all()).await {\n        let Ok(event) = item else {\n            tracing::warn!(source = ?item.unwrap_err(), \"error receiving event\");\n\n            continue;\n        };\n\n        // Update the cache with the event.\n        cache.update(\u0026event);\n\n        tokio::spawn(handle_event(event, Arc::clone(\u0026http)));\n    }\n\n    Ok(())\n}\n\nasync fn handle_event(\n    event: Event,\n    http: Arc\u003cHttpClient\u003e,\n) -\u003e Result\u003c(), Box\u003cdyn Error + Send + Sync\u003e\u003e {\n    match event {\n        Event::MessageCreate(msg) if msg.content == \"!ping\" =\u003e {\n            http.create_message(msg.channel_id)\n                .content(\"Pong!\")\n                .await?;\n        }\n        // Other events here...\n        _ =\u003e {}\n    }\n\n    Ok(())\n}\n```\n\n## License\n\nAll first-party crates are licensed under [ISC][LICENSE.md]\n\n[LICENSE.md]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md\n[Lavalink]: https://github.com/freyacodes/Lavalink\n[`http`]: https://crates.io/crates/http\n[crates:cache-inmemory]: https://crates.io/crates/twilight-cache-inmemory\n[crates:gateway]: https://crates.io/crates/twilight-gateway\n[crates:http]: https://crates.io/crates/twilight-http\n[crates:model]: https://crates.io/crates/twilight-model\n[codecov badge]: https://img.shields.io/codecov/c/gh/twilight-rs/twilight?logo=codecov\u0026style=for-the-badge\u0026token=E9ERLJL0L2\n[codecov link]: https://app.codecov.io/gh/twilight-rs/twilight/\n[discord badge]: https://img.shields.io/discord/745809834183753828?color=%237289DA\u0026label=discord%20server\u0026logo=discord\u0026style=for-the-badge\n[discord link]: https://discord.gg/7jj8n7D\n[github badge]: https://img.shields.io/badge/github-twilight-6f42c1.svg?style=for-the-badge\u0026logo=github\n[github link]: https://github.com/twilight-rs/twilight\n[license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge\u0026logo=pastebin\n[license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md\n[logo]: https://raw.githubusercontent.com/twilight-rs/twilight/main/logo.png\n[rust badge]: https://img.shields.io/badge/rust-1.79+-93450a.svg?style=for-the-badge\u0026logo=rust\n[`twilight-cache-inmemory`]: https://twilight.rs/chapter_1_crates/section_4_cache_inmemory.html\n[`twilight-gateway-queue`]: https://twilight.rs/chapter_1_crates/section_7_first_party/section_5_gateway_queue.html\n[`twilight-gateway`]: https://twilight.rs/chapter_1_crates/section_3_gateway.html\n[`twilight-http`]: https://twilight.rs/chapter_1_crates/section_2_http.html\n[`twilight-lavalink`]: https://twilight.rs/chapter_1_crates/section_7_first_party/section_3_lavalink.html\n[`twilight-mention`]: https://twilight.rs/chapter_1_crates/section_7_first_party/section_2_mention.html\n[`twilight-model`]: https://twilight.rs/chapter_1_crates/section_1_model.html\n[`twilight-standby`]: https://twilight.rs/chapter_1_crates/section_6_standby.html\n[`twilight-util`]: https://twilight.rs/chapter_1_crates/section_7_first_party/section_4_util.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwilight-rs%2Ftwilight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwilight-rs%2Ftwilight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwilight-rs%2Ftwilight/lists"}