A send event is an event that your Discord Bot can send to the Discord Gateway.
Disgo provides a simple way to send events from a Discord Bot.
Suppose that your Discord Bot sends a request to Discord:
- Disgo sends an event to Discord's Gateway.
- Discord's Gateway Server processes the sent event based on several factors (e.g., opcode, payload data).
- Discord's Gateway Server returns a payload with an opcode and payload data to the Discord Bot.
- Disgo handles the incoming event payload to provide you with the requested data.
Disgo automatically handles send event rate limits so your bot isn't blacklisted from Discord.
A send event is sent using the SendEvent(bot)
function.
Disgo is a 1:1 API, meaning the objects defined in the Discord API Documentation are directly represented in Disgo. For example, a RequestGuildMembers
can be prepared and sent using the following code:
// Create a Request Guild Members send event.
sendevent := disgo.RequestGuildMembers{
GuildID: "GUILD",
Query: disgo.Pointer(""),
Limit: disgo.Pointer(0),
}
// Send the Request Guild Members event to Discord using the bot and a connected session or shard manager.
if err := sendevent.SendEvent(bot, session); err != nil {
log.Printf("failure sending SendEvent to Discord: %v", err)
}
Read "Requests: What is a Rate Limit?" for in-depth information about rate limits.
Servers use rate limits to prevent spam, abuse, and service overload. A rate limit defines the speed at which a server can handle events (in requests per second).
The Discord rate limit strategies for send events include:
Disgo makes adhering to Discord's Rate Limits easy by providing a customizable rate limiter:
- Use the builtin
RateLimit
implementation or develop your own by implementing theRateLimiter interface
(which stores Buckets). - Set the
Client.Gateway.RateLimiter
orSession.RateLimiter
to customize how rate limiting works for Gateway Send Events.
The global rate limiter for the Discord Gateway is automatically configured when a disgo.Session
connects to the Discord Gateway.
The Identify
rate limit operates under the following conditions:
- Identify Send Event Rate Limit is applied per application (bot token).
- Identify Send Events count towards the Global Rate Limit for the Discord Gateway.
- Identify Send Event Rate Limit Buckets are reset every 5 seconds.
The bot rate limiter for Identify payloads is configured in the Client.Gateway.RateLimiter
.