Class GatewayClient
The GatewayClient class allows applications to send and receive data from the Discord Gateway, such as events and resource requests.
public class GatewayClient : WebSocketClient, IDisposable, IEntity
- Inheritance
-
GatewayClient
- Implements
- Inherited Members
- Extension Methods
Constructors
GatewayClient(IEntityToken, GatewayClientConfiguration?)
Constructs a GatewayClient using the given token
and configuration
.
public GatewayClient(IEntityToken token, GatewayClientConfiguration? configuration = null)
Parameters
token
IEntityTokenconfiguration
GatewayClientConfiguration
Properties
ApplicationFlags
The application flags of the GatewayClient.
public ApplicationFlags ApplicationFlags { get; }
Property Value
Cache
The cache of the GatewayClient.
public IGatewayClientCache Cache { get; }
Property Value
CreatedAt
The time this object was created.
public DateTimeOffset CreatedAt { get; }
Property Value
Id
The unique identifier for this object.
public ulong Id { get; }
Property Value
Rest
The RestClient of the GatewayClient.
public RestClient Rest { get; }
Property Value
SequenceNumber
The sequence number of the GatewayClient.
public int SequenceNumber { get; }
Property Value
SessionId
The session ID of the GatewayClient.
public string? SessionId { get; }
Property Value
Shard
The shard of the GatewayClient.
public Shard? Shard { get; }
Property Value
Token
The token of the GatewayClient.
public IEntityToken Token { get; }
Property Value
Methods
Dispose(bool)
protected override void Dispose(bool disposing)
Parameters
disposing
bool
RequestGuildUsersAsync(GuildUsersRequestProperties, WebSocketPayloadProperties?, CancellationToken)
Requests users for a guild.
public ValueTask RequestGuildUsersAsync(GuildUsersRequestProperties requestProperties, WebSocketPayloadProperties? properties = null, CancellationToken cancellationToken = default)
Parameters
requestProperties
GuildUsersRequestPropertiesproperties
WebSocketPayloadPropertiescancellationToken
CancellationToken
Returns
ResumeAsync(string, int, CancellationToken)
Resumes the session specified by sessionId
.
public Task ResumeAsync(string sessionId, int sequenceNumber, CancellationToken cancellationToken = default)
Parameters
sessionId
stringThe session to resume.
sequenceNumber
intThe sequence number of the payload to resume from.
cancellationToken
CancellationTokenThe cancellation token to cancel the operation.
Returns
StartAsync(PresenceProperties?, CancellationToken)
Starts the GatewayClient.
public Task StartAsync(PresenceProperties? presence = null, CancellationToken cancellationToken = default)
Parameters
presence
PresencePropertiesThe presence to set.
cancellationToken
CancellationTokenThe cancellation token to cancel the operation.
Returns
UpdatePresenceAsync(PresenceProperties, WebSocketPayloadProperties?, CancellationToken)
Updates an app's presence.
public ValueTask UpdatePresenceAsync(PresenceProperties presence, WebSocketPayloadProperties? properties = null, CancellationToken cancellationToken = default)
Parameters
presence
PresencePropertiesThe presence to set.
properties
WebSocketPayloadPropertiescancellationToken
CancellationTokenThe cancellation token to cancel the operation.
Returns
UpdateVoiceStateAsync(VoiceStateProperties, WebSocketPayloadProperties?, CancellationToken)
Joins, moves, or disconnects the app from a voice channel.
public ValueTask UpdateVoiceStateAsync(VoiceStateProperties voiceState, WebSocketPayloadProperties? properties = null, CancellationToken cancellationToken = default)
Parameters
voiceState
VoiceStatePropertiesproperties
WebSocketPayloadPropertiescancellationToken
CancellationToken
Returns
Events
ApplicationCommandPermissionsUpdate
Sent when an application command's permissions are updated. The inner payload is an ApplicationCommandPermission object.
public event Func<ApplicationCommandPermission, ValueTask>? ApplicationCommandPermissionsUpdate
Event Type
Remarks
Required Intents: None
Optional Intents: None
AutoModerationActionExecution
Sent when a rule is triggered and an action is executed (e.g. when a message is blocked).
public event Func<AutoModerationActionExecutionEventArgs, ValueTask>? AutoModerationActionExecution
Event Type
Remarks
Required Intents: AutoModerationExecution
Optional Intents:
- MessageContent For receiving Content and MatchedContent.
AutoModerationRuleCreate
Sent when a rule is created.
The inner payload is an AutoModerationRule object.
public event Func<AutoModerationRule, ValueTask>? AutoModerationRuleCreate
Event Type
Remarks
Required Intents: AutoModerationConfiguration
Optional Intents: None
AutoModerationRuleDelete
Sent when a rule is deleted.
The inner payload is an AutoModerationRule object.
public event Func<AutoModerationRule, ValueTask>? AutoModerationRuleDelete
Event Type
Remarks
Required Intents: AutoModerationConfiguration
Optional Intents: None
AutoModerationRuleUpdate
Sent when a rule is updated.
The inner payload is an AutoModerationRule object.
public event Func<AutoModerationRule, ValueTask>? AutoModerationRuleUpdate
Event Type
Remarks
Required Intents: AutoModerationConfiguration
Optional Intents: None
ChannelPinsUpdate
Sent when a message is pinned or unpinned in a text channel. This is not sent when a pinned message is deleted.
public event Func<ChannelPinsUpdateEventArgs, ValueTask>? ChannelPinsUpdate
Event Type
Remarks
Required Intents: Guilds, DirectMessages
Optional Intents: None
CurrentUserUpdate
Sent when properties about the current bot's user change.
Inner payload is a CurrentUser object.
public event Func<CurrentUser, ValueTask>? CurrentUserUpdate
Event Type
Remarks
Required Intents: None
Optional Intents: None
EntitlementCreate
Sent when an entitlement is created.
The inner payload is an Entitlement object.
public event Func<Entitlement, ValueTask>? EntitlementCreate
Event Type
Remarks
Required Intents: None
Optional Intents: None
EntitlementDelete
Sent when an entitlement is deleted. Entitlements are not deleted when they expire.
The inner payload is an Entitlement object.
public event Func<Entitlement, ValueTask>? EntitlementDelete
Event Type
Remarks
Required Intents: None
Optional Intents: None
EntitlementUpdate
Sent when an entitlement is updated. When an entitlement for a subscription is renewed, the EndsAt field may have an updated value with the new expiration date.
The inner payload is an Entitlement object.
public event Func<Entitlement, ValueTask>? EntitlementUpdate
Event Type
Remarks
Required Intents: None
Optional Intents: None
GuildAuditLogEntryCreate
Sent when a guild audit log entry is created.
The inner payload is an AuditLogEntry object. This event is only sent to bots with the ViewAuditLog permission.
public event Func<AuditLogEntry, ValueTask>? GuildAuditLogEntryCreate
Event Type
Remarks
Required Intents: GuildModeration
Optional Intents: None
GuildBanAdd
Sent when a user is banned from a guild.
public event Func<GuildBanEventArgs, ValueTask>? GuildBanAdd
Event Type
Remarks
Required Intents: GuildModeration
Optional Intents: None
GuildBanRemove
Sent when a user is unbanned from a guild.
public event Func<GuildBanEventArgs, ValueTask>? GuildBanRemove
Event Type
Remarks
Required Intents: GuildModeration
Optional Intents: None
GuildChannelCreate
Sent when a new guild channel is created, relevant to the bot.
The inner payload is an IGuildChannel object.
public event Func<IGuildChannel, ValueTask>? GuildChannelCreate
Event Type
Remarks
Required Intents: Guilds
Optional Intents: None
GuildChannelDelete
Sent when a channel relevant to the bot is deleted.
The inner payload is an IGuildChannel object.
public event Func<IGuildChannel, ValueTask>? GuildChannelDelete
Event Type
Remarks
Required Intents: Guilds
Optional Intents: None
GuildChannelUpdate
Sent when a channel is updated. This is not sent with new messages, those are tracked by MessageCreate and GuildThreadCreate. This event may reference roles or guild members that no longer exist in the guild.
The inner payload is an IGuildChannel object.
public event Func<IGuildChannel, ValueTask>? GuildChannelUpdate
Event Type
Remarks
Required Intents: Guilds
Optional Intents: None
GuildCreate
This event can be sent in three different scenarios (During an outage, the Guild object in scenarios 1 and 3 may be marked as unavailable):
- To lazily load and backfill information for all unavailable guilds sent in the Ready event. Guilds unavailable due to an outage will send a GuildDelete event.
- When a guild becomes available again to the client.
- When the current user joins a new guild.
public event Func<GuildCreateEventArgs, ValueTask>? GuildCreate
Event Type
Remarks
The inner payload can be a Guild object with extra fields, or an unavailable Guild object. If the guild has over 75k users, users and presences returned in this event will only contain your bot and users in voice channels.
Required Intents: Guilds
Optional Intents:
- GuildPresences For receiving users and presences other than the bot's user and users in voice channels (Same as the 75k limit).
GuildDelete
Sent when a guild becomes or was already unavailable due to an outage, or when the bot leaves / is removed from a guild.
public event Func<GuildDeleteEventArgs, ValueTask>? GuildDelete
Event Type
Remarks
The inner payload is an unavailable guild object. If the IsUserDeleted field is not true, the bot was removed from the guild.
Required Intents: Guilds
Optional Intents: None
GuildEmojisUpdate
Sent when a guild's emojis have been updated.
public event Func<GuildEmojisUpdateEventArgs, ValueTask>? GuildEmojisUpdate
Event Type
Remarks
Required Intents: GuildEmojisAndStickers
Optional Intents: None
GuildIntegrationCreate
Sent when an integration is created.
The inner payload is an integration object with a set GuildId.
public event Func<GuildIntegrationEventArgs, ValueTask>? GuildIntegrationCreate
Event Type
Remarks
Required Intents: GuildIntegrations
Optional Intents: None
GuildIntegrationDelete
Sent when an integration is deleted.
public event Func<GuildIntegrationDeleteEventArgs, ValueTask>? GuildIntegrationDelete
Event Type
Remarks
Required Intents: GuildIntegrations
Optional Intents: None
GuildIntegrationUpdate
Sent when an integration is updated.
The inner payload is an integration object with a set GuildId.
public event Func<GuildIntegrationEventArgs, ValueTask>? GuildIntegrationUpdate
Event Type
Remarks
Required Intents: GuildIntegrations
Optional Intents: None
GuildIntegrationsUpdate
Sent when guild integrations are updated.
public event Func<GuildIntegrationsUpdateEventArgs, ValueTask>? GuildIntegrationsUpdate
Event Type
Remarks
Required Intents: GuildIntegrations
Optional Intents: None
GuildJoinRequestDelete
Not documented by Discord.
public event Func<GuildJoinRequestDeleteEventArgs, ValueTask>? GuildJoinRequestDelete
Event Type
GuildJoinRequestUpdate
Not documented by Discord.
public event Func<GuildJoinRequestUpdateEventArgs, ValueTask>? GuildJoinRequestUpdate
Event Type
GuildScheduledEventCreate
Sent when a guild scheduled event is created.
The inner payload is a GuildScheduledEvent object.
public event Func<GuildScheduledEvent, ValueTask>? GuildScheduledEventCreate
Event Type
Remarks
Required Intents: GuildScheduledEvents
Optional Intents: None
GuildScheduledEventDelete
Sent when a guild scheduled event is deleted.
The inner payload is a GuildScheduledEvent object.
public event Func<GuildScheduledEvent, ValueTask>? GuildScheduledEventDelete
Event Type
Remarks
Required Intents: GuildScheduledEvents
Optional Intents: None
GuildScheduledEventUpdate
Sent when a guild scheduled event is updated.
The inner payload is a GuildScheduledEvent object.
public event Func<GuildScheduledEvent, ValueTask>? GuildScheduledEventUpdate
Event Type
Remarks
Required Intents: GuildScheduledEvents
Optional Intents: None
GuildScheduledEventUserAdd
Sent when a user has subscribed to a guild scheduled event.
public event Func<GuildScheduledEventUserEventArgs, ValueTask>? GuildScheduledEventUserAdd
Event Type
Remarks
Required Intents: GuildScheduledEvents
Optional Intents: None
GuildScheduledEventUserRemove
Sent when a user has unsubscribed from a guild scheduled event.
public event Func<GuildScheduledEventUserEventArgs, ValueTask>? GuildScheduledEventUserRemove
Event Type
Remarks
Required Intents: GuildScheduledEvents
Optional Intents: None
GuildStickersUpdate
Sent when a guild's stickers have been updated.
public event Func<GuildStickersUpdateEventArgs, ValueTask>? GuildStickersUpdate
Event Type
Remarks
Required Intents: GuildEmojisAndStickers
Optional Intents: None
GuildThreadCreate
Sent when a thread is created, relevant to the bot, or when the current user is added to a thread.
The inner payload is an IGuildChannel object.
public event Func<GuildThreadCreateEventArgs, ValueTask>? GuildThreadCreate
Event Type
Remarks
Required Intents: Guilds
Optional Intents: None
GuildThreadDelete
Sent when a thread relevant to the bot is deleted.
The inner payload is a subset of an IGuildChannel object.
public event Func<GuildThreadDeleteEventArgs, ValueTask>? GuildThreadDelete
Event Type
Remarks
Required Intents: Guilds
Optional Intents: None
GuildThreadListSync
Sent when the current user gains access to a channel.
public event Func<GuildThreadListSyncEventArgs, ValueTask>? GuildThreadListSync
Event Type
Remarks
Required Intents: Guilds
Optional Intents: None
GuildThreadUpdate
Sent when a thread is updated. This is not sent with new messages, those are tracked by MessageCreate.
The inner payload is an IGuildChannel object.
public event Func<GuildThread, ValueTask>? GuildThreadUpdate
Event Type
Remarks
Required Intents: Guilds
Optional Intents: None
GuildThreadUserUpdate
Sent when the GuildThreadUser object for the bot is updated. This event is largely just a signal that you are a member of the thread.
The inner payload is a GuildThreadUserUpdateEventArgs object with a set GuildId.
public event Func<GuildThreadUserUpdateEventArgs, ValueTask>? GuildThreadUserUpdate
Event Type
Remarks
Required Intents: Guilds
Optional Intents: None
GuildThreadUsersUpdate
Sent when anyone is added to or removed from a thread.
public event Func<GuildThreadUsersUpdateEventArgs, ValueTask>? GuildThreadUsersUpdate
Event Type
Remarks
Required Intents: Guilds, GuildUsers*
Optional Intents:
- GuildUsers For receiving this event when other users are added / removed, otherwise this event will only fire for the bot's user.
*Must also be enabled in the developer portal.
GuildUpdate
Sent when a guild is updated.
The inner payload is a Guild object.
public event Func<Guild, ValueTask>? GuildUpdate
Event Type
Remarks
Required Intents: Guilds
Optional Intents: None
GuildUserAdd
Sent when a new user joins a guild.
The inner payload is a GuildUser object with an extra guild_id
key.
public event Func<GuildUser, ValueTask>? GuildUserAdd
Event Type
Remarks
Required Intents: GuildUsers*
Optional Intents: None
*Must also be enabled in the developer portal.
GuildUserChunk
Sent in response to RequestGuildUsersAsync(GuildUsersRequestProperties, WebSocketPayloadProperties?, CancellationToken). You can use the ChunkIndex and ChunkCount to calculate how many chunks are left for your request.
public event Func<GuildUserChunkEventArgs, ValueTask>? GuildUserChunk
Event Type
Remarks
Required Intents: None
Optional Intents: None
GuildUserRemove
Sent when a user is removed from a guild (leave/kick/ban).
public event Func<GuildUserRemoveEventArgs, ValueTask>? GuildUserRemove
Event Type
Remarks
Required Intents: GuildUsers*
Optional Intents: None
*Must also be enabled in the developer portal.
GuildUserUpdate
Sent when a guild user is updated. This will also fire when the GuildUser object of a guild user changes.
public event Func<GuildUser, ValueTask>? GuildUserUpdate
Event Type
Remarks
Required Intents: GuildUsers*
Optional Intents: None
*Must also be enabled in the developer portal.
InteractionCreate
Sent when a user uses an interaction.
Inner payload is an Interaction.
public event Func<Interaction, ValueTask>? InteractionCreate
Event Type
Remarks
Required Intents: None
Optional Intents: None
InviteCreate
Sent when a new invite to a channel is created. Only sent if the bot has the ManageChannels permission for the relevant channel.
public event Func<Invite, ValueTask>? InviteCreate
Event Type
Remarks
Required Intents: GuildInvites
Optional Intents: None
InviteDelete
Sent when an invite is deleted. Only sent if the bot has the ManageChannels permission for the relevant channel.
public event Func<InviteDeleteEventArgs, ValueTask>? InviteDelete
Event Type
Remarks
Required Intents: GuildInvites
Optional Intents: None
MessageCreate
Sent when a message is created.
The inner payload is a message object with set GuildId, and Author fields.
public event Func<Message, ValueTask>? MessageCreate
Event Type
Remarks
Required Intents: GuildMessages, DirectMessages*
Optional Intents:
-
MessageContent
For receiving Content, Embeds, Attachments and Embeds.
This does not apply to:- Content in messages sent by the bot.
- Content in DMs with the bot.
- Content in which the bot is mentioned.
- Content of messages a message context menu command is used on.
*Ephemeral messages do not use the guild channel. Because of this, they are tied to the DirectMessages intent, and the message object won't include a GuildId or Author.
MessageDelete
Sent when a message is deleted.
public event Func<MessageDeleteEventArgs, ValueTask>? MessageDelete
Event Type
Remarks
Required Intents: GuildMessages, DirectMessages
Optional Intents: None
MessageDeleteBulk
Sent when multiple messages are deleted at once.
public event Func<MessageDeleteBulkEventArgs, ValueTask>? MessageDeleteBulk
Event Type
Remarks
Required Intents: GuildMessages
Optional Intents: None
MessagePollVoteAdd
public event Func<MessagePollVoteEventArgs, ValueTask>? MessagePollVoteAdd
Event Type
MessagePollVoteRemove
public event Func<MessagePollVoteEventArgs, ValueTask>? MessagePollVoteRemove
Event Type
MessageReactionAdd
Sent when a user adds a reaction to a message.
public event Func<MessageReactionAddEventArgs, ValueTask>? MessageReactionAdd
Event Type
Remarks
Required Intents: GuildMessageReactions, DirectMessageReactions
Optional Intents: None
MessageReactionRemove
Sent when a user removes a reaction from a message.
public event Func<MessageReactionRemoveEventArgs, ValueTask>? MessageReactionRemove
Event Type
Remarks
Required Intents: GuildMessageReactions, DirectMessageReactions
Optional Intents: None
MessageReactionRemoveAll
Sent when a user explicitly removes all reactions from a message.
public event Func<MessageReactionRemoveAllEventArgs, ValueTask>? MessageReactionRemoveAll
Event Type
Remarks
Required Intents: GuildMessageReactions, DirectMessageReactions
Optional Intents: None
MessageReactionRemoveEmoji
Sent when a user removes all instances of a given emoji from the reactions of a message.
public event Func<MessageReactionRemoveEmojiEventArgs, ValueTask>? MessageReactionRemoveEmoji
Event Type
Remarks
Required Intents: GuildMessageReactions, DirectMessageReactions
Optional Intents: None
MessageUpdate
Sent when a message is updated.
The inner payload is a message object with set GuildId, and Author fields.
public event Func<Message, ValueTask>? MessageUpdate
Event Type
Remarks
Required Intents: GuildMessages, DirectMessages*
Optional Intents:
-
MessageContent
For receiving Content, Embeds, Attachments and Embeds.
This does not apply to:- Content in messages sent by the bot.
- Content in DMs with the bot.
- Content in which the bot is mentioned.
- Content of messages a message context menu command is used on.
*Ephemeral messages do not use the guild channel. Because of this, they are tied to the DirectMessages intent, and the message object won't include a GuildId or Author.
PresenceUpdate
Sent when a user's presence or info, such as their name or avatar, is updated. Requires the GuildPresences intent.
The user object within this event can be partial, with the ID being the only required field, everything else is optional. Along with this limitation, no fields are required, and the types of the fields are not validated. You should expect any combination of fields and types within this event.
public event Func<Presence, ValueTask>? PresenceUpdate
Event Type
Remarks
Required Intents: GuildPresences*
Optional Intents: None
*Must also be enabled in the developer portal.
Ready
The ready event is dispatched when a client has completed the initial handshake with the Gateway (for new sessions). The ready event contains all the state required for a client to begin interacting with the rest of the platform.
public event Func<ReadyEventArgs, ValueTask>? Ready
Event Type
Remarks
Required Intents: None
Optional Intents: None
RoleCreate
Sent when a guild role is created.
public event Func<Role, ValueTask>? RoleCreate
Event Type
Remarks
Required Intents: Guilds
Optional Intents: None
RoleDelete
Sent when a guild role is deleted.
public event Func<RoleDeleteEventArgs, ValueTask>? RoleDelete
Event Type
Remarks
Required Intents: Guilds
Optional Intents: None
RoleUpdate
Sent when a guild role is updated.
public event Func<Role, ValueTask>? RoleUpdate
Event Type
Remarks
Required Intents: Guilds
Optional Intents: None
StageInstanceCreate
Sent when a StageInstance is created (i.e. the Stage is now 'live').
Inner payload is a StageInstance.
public event Func<StageInstance, ValueTask>? StageInstanceCreate
Event Type
Remarks
Required Intents: Guilds
Optional Intents: None
StageInstanceDelete
Sent when a StageInstance is deleted (i.e. the Stage has been closed).
Inner payload is a StageInstance.
public event Func<StageInstance, ValueTask>? StageInstanceDelete
Event Type
Remarks
Required Intents: Guilds
Optional Intents: None
StageInstanceUpdate
Sent when a StageInstance is updated.
Inner payload is a StageInstance.
public event Func<StageInstance, ValueTask>? StageInstanceUpdate
Event Type
Remarks
Required Intents: Guilds
Optional Intents: None
TypingStart
Sent when a user starts typing in a channel, and fires again every 10 seconds while they continue typing.
public event Func<TypingStartEventArgs, ValueTask>? TypingStart
Event Type
Remarks
Required Intents: GuildMessageTyping, DirectMessageTyping
Optional Intents: None
UnknownEvent
An unknown event.
public event Func<UnknownEventEventArgs, ValueTask>? UnknownEvent
Event Type
VoiceChannelEffectSend
Sent when someone sends an effect, such as an emoji reaction or a soundboard sound, in a voice channel the current user is connected to.
Inner payload is a VoiceChannelEffectSendEventArgs object.
public event Func<VoiceChannelEffectSendEventArgs, ValueTask>? VoiceChannelEffectSend
Event Type
Remarks
Required Intents: GuildVoiceStates
Optional Intents: None
VoiceServerUpdate
Sent when a guild's voice server is updated. This is sent when initially connecting to voice, and when the current voice instance fails over to a new server.
public event Func<VoiceServerUpdateEventArgs, ValueTask>? VoiceServerUpdate
Event Type
Remarks
Required Intents: None
Optional Intents: None
VoiceStateUpdate
Sent when someone joins/leaves/moves voice channels.
Inner payload is a VoiceState object.
public event Func<VoiceState, ValueTask>? VoiceStateUpdate
Event Type
Remarks
Required Intents: GuildVoiceStates
Optional Intents: None
WebhooksUpdate
Sent when a guild channel's webhook is created, updated, or deleted.
public event Func<WebhooksUpdateEventArgs, ValueTask>? WebhooksUpdate
Event Type
Remarks
Required Intents: GuildWebhooks
Optional Intents: None