{"id":13414011,"url":"https://github.com/switchupcb/disgo","last_synced_at":"2025-03-18T02:49:22.094Z","repository":{"id":37788013,"uuid":"471909085","full_name":"switchupcb/disgo","owner":"switchupcb","description":"Create a Discord Bot in Go using this Discord API Wrapper.  The next generation of Discord API Consumption.","archived":false,"fork":false,"pushed_at":"2023-07-30T07:38:12.000Z","size":17899,"stargazers_count":86,"open_issues_count":3,"forks_count":2,"subscribers_count":3,"default_branch":"v10","last_synced_at":"2024-05-02T03:16:45.711Z","etag":null,"topics":["discord","discord-api","discord-bot","go"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/switchupcb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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}},"created_at":"2022-03-20T07:29:55.000Z","updated_at":"2024-06-19T00:14:47.818Z","dependencies_parsed_at":"2024-06-19T00:14:40.354Z","dependency_job_id":"e015daec-b83c-4cb7-bfc0-14d52dbea830","html_url":"https://github.com/switchupcb/disgo","commit_stats":{"total_commits":85,"total_committers":4,"mean_commits":21.25,"dds":0.3411764705882353,"last_synced_commit":"349d45654529f2878dca4107f045b7bfe08540e2"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/switchupcb%2Fdisgo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/switchupcb%2Fdisgo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/switchupcb%2Fdisgo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/switchupcb%2Fdisgo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/switchupcb","download_url":"https://codeload.github.com/switchupcb/disgo/tar.gz/refs/heads/v10","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244147365,"owners_count":20405940,"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","go"],"created_at":"2024-07-30T20:01:55.151Z","updated_at":"2025-03-18T02:49:22.067Z","avatar_url":"https://github.com/switchupcb.png","language":"Go","readme":"# Create a Discord Bot with Go\n\n[![Go Doc](https://img.shields.io/badge/godoc-reference-5272B4.svg?style=for-the-badge\u0026logo=appveyor\u0026logo=appveyor)](https://pkg.go.dev/github.com/switchupcb/disgo)\n[![License](https://img.shields.io/github/license/switchupcb/disgo.svg?style=for-the-badge)](https://github.com/switchupcb/disgo/blob/main/LICENSE)\n\n**Disgo** helps you create a Discord Bot with the Go programming language.\n\n## What is Disgo?\n\n**Disgo** is a [Discord API](https://discord.com/developers/docs/reference) Wrapper designed to be flexible, performant, secure, and thread-safe. Disgo provides every feature in the Discord API along with optional rate limiting, structured logging, shard management, and caching. \n\n_This repository is STABLE. For more information, read the [roadmap](/_contribution/CONTRIBUTING.md#roadmap)._\n\n### A Next Generation Discord API Wrapper\n\nUse the only Go module to provide a **100% one-to-one horizontally scalable implementation** of the Discord API.\n\nYour development is also simplified with these exclusive features.\n\n- [EVERY Rate Limit (Global, Per Route, Per Resource, Custom, Gateway)](_contribution/concepts/REQUESTS.md#what-is-a-rate-limit) \n- [Automatic Gateway Intent Calculation](_contribution/concepts/EVENTS.md#what-is-a-gateway-intent)\n- [Selective Event Processing](_contribution/concepts/EVENTS.md#selective-event-processing)\n\n_Disgo uses [NO reflection or type assertion](_contribution/concepts/EVENTS.md#how-it-works)._\n\n### A Next Generation Development Process\n\nDisgo uses developer operations to stay up-to-date with the ever-changing Discord API. \n- Code generation provides an optimal implementation for every request and event.\n- Data race detection is run on _an integration test covering the entire Discord API_ to make Disgo safe for concurrent usage.\n\n## Table of Contents\n\n| Topic                           | Categories                                                                                                                                                             |\n| :------------------------------ | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| [Using the API](#using-the-api) | [Breakdown](#using-the-api), [Logging](#logging), [Sharding](#sharding), [Caching](#caching)                                                                           |\n| [Examples](#examples)           | [Import](#import), [Configuration](#configuration), [Create a Command](#create-a-command), [Handle an Event](#handle-an-event), [Output](#output), [Summary](#Summary) |\n| [Features](#features)           | [Why Go?](#why-go), [Comparison](#comparison), [Contributing](#contributing)                                                                                           |\n| [Ecosystem](#ecosystem)         | [License](#license), [Libraries](#libraries), [Credits](#credits)                                                                                                      |\n\n## Using the API\n\nUse this breakdown to learn how the Discord API works.\n\n| Abstraction  | Usecase                                                                                                                                           | Example                                                                             |\n| :----------- | :------------------------------------------------------------------------------------------------------------------------------------------------ | :---------------------------------------------------------------------------------- |\n| **Resource** | A [Discord API Resource](https://discord.com/developers/docs/resources/application).                                                              | Guild Object. \u003cbr\u003e User Object.                                                     |\n| **Event**    | A [Discord API Event](https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-events).                                     | A message is created. \u003cbr\u003e A user joins a channel.                                  |\n| **Client**   | The Discord Bot [Application](https://discord.com/developers/docs/resources/application) that you develop. \u003cbr\u003e\u003cbr\u003e Bot = Client = Application.   | Configure the bot settings. \u003cbr\u003e \u003cbr\u003e Set the token.                                |\n| **Request**  | Uses the Discord HTTP REST API to make one-time _requests_ for information.                                                                       | Create an application command. \u003cbr\u003e Request guild information.                      |\n| **Session**  | Uses a Discord WebSocket Connection [(Gateway)](https://discord.com/developers/docs/topics/gateway) to receive _events_ that contain information. | Send a message when an application command is used or a user joins a voice channel. |\n\nHere is an example.\n\nYou create a **Client** that **Requests** **Resources** and handles **Events** from **Sessions** using Event Handlers. \n\n_For more information, please read [What is a Request?](/_contribution/concepts/REQUESTS.md) and [What is an Event?](/_contribution/concepts/EVENTS.md)._\n\n### Flags\n\n All flags are denoted by `disgo.Flag` _(e.g., `disgo.FlagUserSTAFF`, `disgo.FlagVerificationLevelHIGH`, `disgo.FlagPremiumTierNONE`)_.\n\nA flag is a [flag](https://discord.com/developers/docs/resources/application#application-object-application-flags), [type](https://discord.com/developers/docs/resources/channel#embed-object-embed-types), [key](https://discord.com/developers/docs/resources/audit-log#audit-log-change-object-audit-log-change-key), [level](https://discord.com/developers/docs/resources/guild#guild-object-verification-level) or any other option that Discord provides.\n\n### Logging\n\nDisgo provides structured, leveled logging of the API Wrapper via the `disgo.Logger` global variable _(disabled by default)_. Enable the logger using `zerolog.SetGlobalLevel(zerolog.LEVEL)`.\n\n_Read [What is a Log](/_contribution/concepts/LOG.md) for a simple yet full understanding of logging._\n\n### Sharding\n\nUsing the automatic [Shard Manager](/_contribution/concepts/SHARD.md#the-shard-manager) is **optional** and **customizable**.\n\n_Read [What is a Discord Shard](/_contribution/concepts/SHARD.md) for a simple yet full understanding of sharding on Discord._\n\n### Caching\n\nThe [Disgo Cache](/_contribution/concepts/CACHE.md#the-disgo-cache) is **optional** and **customizable**.\n\nThe **cache interface** lets you replace the built-in cache with another store _(such as Redis or Memcached)_ or provide your own caching implementation.\n\n_Read [What is a Cache](/_contribution/concepts/CACHE.md) for a simple yet full understanding of the Disgo Cache._\n\n## Examples\n\n| Example                        | Description                                                |\n| :----------------------------- | :--------------------------------------------------------- |\n| main                           | Learn how to use `disgo`.                                  |\n| [command](/_examples/command/) | Create an application command and respond to interactions. |\n| [message](/_examples/message/) | Send a message with text, emojis, files, and components.   |\n| [image](/_examples/image/)     | Set the bot's avatar using an image.                       |\n\n_Check out the [examples](/_examples/) directory for more examples._\n\n### Import\n\nGet a specific version of `disgo` by specifying a tag or branch.\n\n```\ngo get github.com/switchupcb/disgo@v1.10.21\n```\n\n_Disgo branches are referenced by API version (i.e `v10`)._\n\n### Configuration\n\n_**You must create a Discord Application in the [Discord Developer Portal](https://discord.com/developers/docs/getting-started#creating-an-app) to receive your Bot Token.**_\n\nUse the client to configure the bot's settings.\n\n```go\nbot := \u0026disgo.Client{\n    ApplicationID:  \"APPID\", // optional\n    Authentication: disgo.BotToken(\"TOKEN\"), // or BearerToken(\"TOKEN\")\n    Authorization:  \u0026disgo.Authorization{ ... },\n    Config:         disgo.DefaultConfig(),\n    Handlers:       new(disgo.Handlers),\n    VoiceHandlers:  new(disgo.VoiceHandlers),\n    Sessions:       disgo.NewSessionManager()\n}\n```\n\n_Need more information about configuration? Check out the [bot example](/_examples/bot)._\n\n### Create a Command\n\nCreate an application command **request** to add an application command.\n\n```go\n// Create a Create Global Application Command request.\nrequest := disgo.CreateGlobalApplicationCommand{\n    Name:        \"main\",\n    Description: disgo.Pointer(\"A basic command.\"),\n}\n\n// Register the new command by sending the request to Discord using the bot.\n//\n// returns a disgo.ApplicationCommand\nnewCommand, err := request.Send(bot)\nif err != nil {\n    log.Printf(\"failure sending command to Discord: %v\", err)\n\n    return\n}\n```\n\n### Handle an Event\n\nCreate an **event handler** and add it to the **bot**.\n\n```go\n// Add an event handler to the bot.\nbot.Handle(disgo.FlagGatewayEventNameInteractionCreate, func(i *disgo.InteractionCreate) {\n\tlog.Printf(\"main called by %s\", i.User.Username)\n})\n```\n\n_Disgo provides automatic [Gateway Intent](https://discord.com/developers/docs/topics/gateway#gateway-intents) calculation._\n\n### Output\n\nOpen a WebSocket **Session** to receive and send events.\n\n```go\n// Connect a new session to the Discord Gateway (WebSocket Connection).\ns := disgo.NewSession()\nif err := s.Connect(bot); err != nil {\n    log.Printf(\"can't open websocket session to Discord Gateway: %v\", err)\n\n    return\n}\n```\n\nThe following message will be logged when a user creates an `InteractionCreate` event by using `/main` in a Direct Message with the Bot on Discord.\n\n```\nmain called by switchupcb.\n```\n\n### Summary\n\n```go\n// Use flags to specify options from Discord.\ndisgo.Flag\u003cOption\u003e\u003cName\u003e\n\n// Use resources to represent Discord objects in your application.\ndisgo.\u003cAPI Resources\u003e\n\n// Use events to represent Discord events in your application.\ndisgo.\u003cAPI Events\u003e\n\n// Use requests to exchange data with Discord's REST API.\ndisgo.\u003cEndpoint\u003e.Send()\n\n// Use sessions to connect to the Discord Gateway.\ndisgo.Session.Connect()\ndisgo.Session.Disconnect()\n\n// Use send events to send data to Discord's Gateway.\ndisgo.\u003cEvent\u003e.SendEvent()\n\n// Use event handlers to handle events from Discord's Gateway.\ndisgo.Client.Handle(\u003cevent\u003e, \u003chandler\u003e)\ndisgo.Client.Remove(\u003cevent\u003e, \u003cindex\u003e)\ndisgo.Client.Handlers.\u003cHandler\u003e\ndisgo.Client.VoiceHandlers.\u003cHandler\u003e\n\n// Use the client to manage the bot's settings.\ndisgo.Client.ApplicationID\ndisgo.Client.Authentication.\u003cSettings\u003e\ndisgo.Client.Authorization.\u003cSettings\u003e\ndisgo.Client.Config.Request.\u003cSettings\u003e\ndisgo.Client.Config.Gateway.\u003cSettings\u003e\n```\n\n## Features\n\n### Why Go?\n\n**A Discord Bot is server-side software.**\n\nA server-side software uses asynchronous logic to operate.\nGo maintains superior asynchronous handling with [Goroutines](https://gobyexample.com/goroutines) and [Channels](https://gobyexample.com/channels).\n\nGo is a statically typed, compiled programming language _(with a garbage collector)_. So, it also performs better computationally compared to _most_ languages that provide [Discord API Wrappers](https://discord.com/developers/docs/topics/community-resources#libraries).\n\n### How does Disgo compare to other Go Discord API Wrappers?\n\nDisgo supports every feature in the Discord API and is **the most customizable Discord API Wrapper** due to its optional caching, shard management, rate limiting, and logging.\n\nMost important is Disgo's performance, which saves you money by reducing server costs. \n\n_Don't believe me? Check this out!_\n\n#### CPU\n\nDisgo places a priority on performance. For more information, view [`library decisions`](/_contribution/libraries/).\n\n### Memory\n\nEvery struct uses [fieldalignment](https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/fieldalignment) to reduce the memory footprint of your application.\n\n### Storage\n\nDisgo adds **5 MB** to a compiled binary.\n\n### Contributing\n\nDisgo is the easiest Discord Go API for developers to use and contribute to: You can contribute to this repository by viewing the [Project Structure, Code Specifications, and Roadmap](/_contribution/CONTRIBUTING.md).\n\n## Ecosystem\n\n### License\n\nThe [Apache License 2.0](#license) is permissive for commercial use. For more information, read [Apache Licensing FAQ](https://www.apache.org/foundation/license-faq.html).\n\n### Libraries\n\n| Library                                               | Description                              |\n| :---------------------------------------------------- | :--------------------------------------- |\n| [Copygen](https://github.com/switchupcb/copygen)      | Generate custom type-based code.         |\n| [Dasgo](https://github.com/switchupcb/dasgo)          | Go Type Definitions for the Discord API. |\n| [Ecosystem](https://github.com/switchupcb/disgo/wiki) | View projects that use Disgo.            |\n\n### Credits\n\n| Name                                      | Contributions                                                            |\n| :---------------------------------------- | :----------------------------------------------------------------------- |\n| [SwitchUpCB](https://switchupcb.com)      | Project Architecture, Generators, Dasgo, Requests, Events, Voice Connection, Shard Manager |\n| [Thomas Rogers](https://github.com/t-rog) | Dasgo                                                                    |\n| [Josh Dawe](https://github.com/joshdawe)  | Dasgo                                                                    |\n\n_Earn a credit! [Contribute Now](_contribution/CONTRIBUTING.md)._\n","funding_links":[],"categories":["Third-party APIs","第三方api"],"sub_categories":["Utility/Miscellaneous","实用程序/Miscellaneous"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswitchupcb%2Fdisgo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswitchupcb%2Fdisgo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswitchupcb%2Fdisgo/lists"}