Table of Contents

Class SocketInteraction

Namespace
Discord.WebSocket
Assembly
Discord.Net.WebSocket.dll

Represents an Interaction received over the gateway.

public abstract class SocketInteraction : SocketEntity<ulong>, IDiscordInteraction, ISnowflakeEntity, IEntity<ulong>
Inheritance
SocketInteraction
Implements
Derived
Inherited Members
Extension Methods

Properties

ApplicationId

Gets the ID of the application this interaction is for.

public ulong ApplicationId { get; }

Property Value

ulong

Channel

Gets the ISocketMessageChannel this interaction was used in.

public ISocketMessageChannel Channel { get; }

Property Value

ISocketMessageChannel

Remarks

If the channel isn't cached, the bot scope isn't used, or the bot doesn't have access to it then this property will be null.

ChannelId

Gets the ID of the channel this interaction was executed in.

public ulong? ChannelId { get; }

Property Value

ulong?

Remarks

This property returns null if the interaction is a REST ping interaction.

ContextType

Gets the context this interaction was created in. null if context type is unknown.

public InteractionContextType? ContextType { get; }

Property Value

InteractionContextType?

CreatedAt

Gets when the snowflake was created.

public DateTimeOffset CreatedAt { get; }

Property Value

DateTimeOffset

A DateTimeOffset representing when the entity was first created.

Data

Gets the data sent within this interaction.

public IDiscordInteractionData Data { get; }

Property Value

IDiscordInteractionData

Entitlements

Gets entitlements for the invoking user.

public IReadOnlyCollection<RestEntitlement> Entitlements { get; }

Property Value

IReadOnlyCollection<RestEntitlement>

GuildId

Gets the ID of the guild this interaction was executed in.

public ulong? GuildId { get; }

Property Value

ulong?

Remarks

This property returns null if the interaction was not executed in a guild.

GuildLocale

Gets the preferred locale of the guild this interaction was executed in. null if not executed in a guild.

public string GuildLocale { get; }

Property Value

string

Remarks

Non-community guilds (With no locale setting available) will have en-US as the default value sent by Discord.

HasResponded

Gets whether or not this interaction has been responded to.

public abstract bool HasResponded { get; }

Property Value

bool

Remarks

This property is locally set -- if you're running multiple bots off the same token then this property won't be in sync with them.

IntegrationOwners

Gets which integrations authorized the interaction.

public IReadOnlyDictionary<ApplicationIntegrationType, ulong> IntegrationOwners { get; }

Property Value

IReadOnlyDictionary<ApplicationIntegrationType, ulong>

IsDMInteraction

Gets whether or not this interaction was executed in a dm channel.

public bool IsDMInteraction { get; }

Property Value

bool

IsValidToken

Gets whether or not the token used to respond to this interaction is valid.

public bool IsValidToken { get; }

Property Value

bool

Permissions

Gets the permissions the app or bot has within the channel the interaction was sent from.

public GuildPermissions Permissions { get; }

Property Value

GuildPermissions

Token

Gets the continuation token for responding to the interaction.

public string Token { get; }

Property Value

string

Type

Gets the type of this IDiscordInteraction.

public InteractionType Type { get; }

Property Value

InteractionType

User

Gets the SocketUser who triggered this interaction.

public SocketUser User { get; }

Property Value

SocketUser

UserLocale

Gets the preferred locale of the invoking User.

public string UserLocale { get; }

Property Value

string

Remarks

This property returns null if the interaction is a REST ping interaction.

Version

Gets the version of the interaction, always 1.

public int Version { get; }

Property Value

int

Methods

DeferAsync(bool, RequestOptions)

Acknowledges this interaction.

public abstract Task DeferAsync(bool ephemeral = false, RequestOptions options = null)

Parameters

ephemeral bool

true to send this message ephemerally, otherwise false.

options RequestOptions

The request options for this async request.

Returns

Task

A task that represents the asynchronous operation of acknowledging the interaction.

DeleteOriginalResponseAsync(RequestOptions)

Deletes the original response to this interaction.

public Task DeleteOriginalResponseAsync(RequestOptions options = null)

Parameters

options RequestOptions

The request options for this async request.

Returns

Task

A task that represents an asynchronous deletion operation.

FollowupAsync(string, Embed[], bool, bool, AllowedMentions, MessageComponent, Embed, RequestOptions)

Sends a followup message for this interaction.

public abstract Task<RestFollowupMessage> FollowupAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null)

Parameters

text string

The text of the message to be sent.

embeds Embed[]

A array of embeds to send with this response. Max 10.

isTTS bool

true if the message should be read out by a text-to-speech reader, otherwise false.

ephemeral bool

true if the response should be hidden to everyone besides the invoker of the command, otherwise false.

allowedMentions AllowedMentions

The allowed mentions for this response.

components MessageComponent

A MessageComponent to be sent with this response.

embed Embed

A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.

options RequestOptions

The request options for this response.

Returns

Task<RestFollowupMessage>

The sent message.

FollowupWithFileAsync(FileAttachment, string, Embed[], bool, bool, AllowedMentions, MessageComponent, Embed, RequestOptions)

Sends a followup message for this interaction.

public Task<RestFollowupMessage> FollowupWithFileAsync(FileAttachment attachment, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null)

Parameters

attachment FileAttachment

The attachment containing the file and description.

text string

The text of the message to be sent.

embeds Embed[]

A array of embeds to send with this response. Max 10.

isTTS bool

true if the message should be read out by a text-to-speech reader, otherwise false.

ephemeral bool

true if the response should be hidden to everyone besides the invoker of the command, otherwise false.

allowedMentions AllowedMentions

The allowed mentions for this response.

components MessageComponent

A MessageComponent to be sent with this response.

embed Embed

A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.

options RequestOptions

The request options for this response.

Returns

Task<RestFollowupMessage>

A task that represents an asynchronous send operation for delivering the message. The task result contains the sent message.

FollowupWithFileAsync(Stream, string, string, Embed[], bool, bool, AllowedMentions, MessageComponent, Embed, RequestOptions)

Sends a followup message for this interaction.

public Task<RestFollowupMessage> FollowupWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null)

Parameters

fileStream Stream

The file to upload.

fileName string

The file name of the attachment.

text string

The text of the message to be sent.

embeds Embed[]

A array of embeds to send with this response. Max 10.

isTTS bool

true if the message should be read out by a text-to-speech reader, otherwise false.

ephemeral bool

true if the response should be hidden to everyone besides the invoker of the command, otherwise false.

allowedMentions AllowedMentions

The allowed mentions for this response.

components MessageComponent

A MessageComponent to be sent with this response.

embed Embed

A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.

options RequestOptions

The request options for this response.

Returns

Task<RestFollowupMessage>

The sent message.

FollowupWithFileAsync(string, string, string, Embed[], bool, bool, AllowedMentions, MessageComponent, Embed, RequestOptions)

Sends a followup message for this interaction.

public Task<RestFollowupMessage> FollowupWithFileAsync(string filePath, string fileName = null, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null)

Parameters

filePath string

The file to upload.

fileName string

The file name of the attachment.

text string

The text of the message to be sent.

embeds Embed[]

A array of embeds to send with this response. Max 10.

isTTS bool

true if the message should be read out by a text-to-speech reader, otherwise false.

ephemeral bool

true if the response should be hidden to everyone besides the invoker of the command, otherwise false.

allowedMentions AllowedMentions

The allowed mentions for this response.

components MessageComponent

A MessageComponent to be sent with this response.

embed Embed

A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.

options RequestOptions

The request options for this response.

Returns

Task<RestFollowupMessage>

The sent message.

FollowupWithFilesAsync(IEnumerable<FileAttachment>, string, Embed[], bool, bool, AllowedMentions, MessageComponent, Embed, RequestOptions)

Sends a followup message for this interaction.

public abstract Task<RestFollowupMessage> FollowupWithFilesAsync(IEnumerable<FileAttachment> attachments, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null)

Parameters

attachments IEnumerable<FileAttachment>

A collection of attachments to upload.

text string

The text of the message to be sent.

embeds Embed[]

A array of embeds to send with this response. Max 10.

isTTS bool

true if the message should be read out by a text-to-speech reader, otherwise false.

ephemeral bool

true if the response should be hidden to everyone besides the invoker of the command, otherwise false.

allowedMentions AllowedMentions

The allowed mentions for this response.

components MessageComponent

A MessageComponent to be sent with this response.

embed Embed

A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.

options RequestOptions

The request options for this response.

Returns

Task<RestFollowupMessage>

A task that represents an asynchronous send operation for delivering the message. The task result contains the sent message.

GetChannelAsync(RequestOptions)

Attempts to get the channel this interaction was executed in.

public ValueTask<IMessageChannel> GetChannelAsync(RequestOptions options = null)

Parameters

options RequestOptions

The request options for this async request.

Returns

ValueTask<IMessageChannel>

A task that represents the asynchronous operation of fetching the channel.

GetOriginalResponseAsync(RequestOptions)

Gets the original response for this interaction.

public Task<RestInteractionMessage> GetOriginalResponseAsync(RequestOptions options = null)

Parameters

options RequestOptions

The request options for this async request.

Returns

Task<RestInteractionMessage>

A RestInteractionMessage that represents the initial response.

ModifyOriginalResponseAsync(Action<MessageProperties>, RequestOptions)

Edits original response for this interaction.

public Task<RestInteractionMessage> ModifyOriginalResponseAsync(Action<MessageProperties> func, RequestOptions options = null)

Parameters

func Action<MessageProperties>

A delegate containing the properties to modify the message with.

options RequestOptions

The request options for this async request.

Returns

Task<RestInteractionMessage>

A RestInteractionMessage that represents the initial response.

RespondAsync(string, Embed[], bool, bool, AllowedMentions, MessageComponent, Embed, RequestOptions)

Responds to an Interaction with type ChannelMessageWithSource.

public abstract Task RespondAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null)

Parameters

text string

The text of the message to be sent.

embeds Embed[]

A array of embeds to send with this response. Max 10.

isTTS bool

true if the message should be read out by a text-to-speech reader, otherwise false.

ephemeral bool

true if the response should be hidden to everyone besides the invoker of the command, otherwise false.

allowedMentions AllowedMentions

The allowed mentions for this response.

components MessageComponent

A MessageComponent to be sent with this response.

embed Embed

A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.

options RequestOptions

The request options for this response.

Returns

Task

Exceptions

ArgumentOutOfRangeException

Message content is too long, length must be less or equal to MaxMessageSize.

InvalidOperationException

The parameters provided were invalid or the token was invalid.

RespondWithFileAsync(FileAttachment, string, Embed[], bool, bool, AllowedMentions, MessageComponent, Embed, RequestOptions)

Responds to this interaction with a file attachment.

public Task RespondWithFileAsync(FileAttachment attachment, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null)

Parameters

attachment FileAttachment

The attachment containing the file and description.

text string

The text of the message to be sent.

embeds Embed[]

A array of embeds to send with this response. Max 10.

isTTS bool

true if the message should be read out by a text-to-speech reader, otherwise false.

ephemeral bool

true if the response should be hidden to everyone besides the invoker of the command, otherwise false.

allowedMentions AllowedMentions

The allowed mentions for this response.

components MessageComponent

A MessageComponent to be sent with this response.

embed Embed

A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.

options RequestOptions

The request options for this response.

Returns

Task

A task that represents an asynchronous send operation for delivering the message. The task result contains the sent message.

RespondWithFileAsync(Stream, string, string, Embed[], bool, bool, AllowedMentions, MessageComponent, Embed, RequestOptions)

Responds to this interaction with a file attachment.

public Task RespondWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null)

Parameters

fileStream Stream

The file to upload.

fileName string

The file name of the attachment.

text string

The text of the message to be sent.

embeds Embed[]

A array of embeds to send with this response. Max 10.

isTTS bool

true if the message should be read out by a text-to-speech reader, otherwise false.

ephemeral bool

true if the response should be hidden to everyone besides the invoker of the command, otherwise false.

allowedMentions AllowedMentions

The allowed mentions for this response.

components MessageComponent

A MessageComponent to be sent with this response.

embed Embed

A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.

options RequestOptions

The request options for this response.

Returns

Task

A task that represents an asynchronous send operation for delivering the message. The task result contains the sent message.

RespondWithFileAsync(string, string, string, Embed[], bool, bool, AllowedMentions, MessageComponent, Embed, RequestOptions)

Responds to this interaction with a file attachment.

public Task RespondWithFileAsync(string filePath, string fileName = null, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null)

Parameters

filePath string

The file to upload.

fileName string

The file name of the attachment.

text string

The text of the message to be sent.

embeds Embed[]

A array of embeds to send with this response. Max 10.

isTTS bool

true if the message should be read out by a text-to-speech reader, otherwise false.

ephemeral bool

true if the response should be hidden to everyone besides the invoker of the command, otherwise false.

allowedMentions AllowedMentions

The allowed mentions for this response.

components MessageComponent

A MessageComponent to be sent with this response.

embed Embed

A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.

options RequestOptions

The request options for this response.

Returns

Task

A task that represents an asynchronous send operation for delivering the message. The task result contains the sent message.

RespondWithFilesAsync(IEnumerable<FileAttachment>, string, Embed[], bool, bool, AllowedMentions, MessageComponent, Embed, RequestOptions)

Responds to this interaction with a collection of file attachments.

public abstract Task RespondWithFilesAsync(IEnumerable<FileAttachment> attachments, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null)

Parameters

attachments IEnumerable<FileAttachment>

A collection of attachments to upload.

text string

The text of the message to be sent.

embeds Embed[]

A array of embeds to send with this response. Max 10.

isTTS bool

true if the message should be read out by a text-to-speech reader, otherwise false.

ephemeral bool

true if the response should be hidden to everyone besides the invoker of the command, otherwise false.

allowedMentions AllowedMentions

The allowed mentions for this response.

components MessageComponent

A MessageComponent to be sent with this response.

embed Embed

A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.

options RequestOptions

The request options for this response.

Returns

Task

A task that represents an asynchronous send operation for delivering the message. The task result contains the sent message.

RespondWithModalAsync(Modal, RequestOptions)

Responds to this interaction with a Modal.

public abstract Task RespondWithModalAsync(Modal modal, RequestOptions options = null)

Parameters

modal Modal

The Modal to respond with.

options RequestOptions

The request options for this async request.

Returns

Task

A task that represents the asynchronous operation of responding to the interaction.

RespondWithPremiumRequiredAsync(RequestOptions)

Responds to the interaction with an ephemeral message the invoking user, instructing them that whatever they tried to do requires the premium benefits of your app.

public Task RespondWithPremiumRequiredAsync(RequestOptions options = null)

Parameters

options RequestOptions

Returns

Task

A task that represents the asynchronous operation of responding to the interaction.