Table of Contents

Class InteractionModuleBase<T>

Namespace
Discord.Interactions
Assembly
Discord.Net.Interactions.dll

Provides a base class for a command module to inherit from.

public abstract class InteractionModuleBase<T> : IInteractionModuleBase where T : class, IInteractionContext

Type Parameters

T

Type of interaction context to be injected into the module.

Inheritance
InteractionModuleBase<T>
Implements
Derived
Inherited Members

Properties

Context

Gets the underlying context of the command.

public T Context { get; }

Property Value

T

Methods

AfterExecute(ICommandInfo)

Method body to be executed after an application command execution.

public virtual void AfterExecute(ICommandInfo command)

Parameters

command ICommandInfo

Command information related to the Discord Application Command.

AfterExecuteAsync(ICommandInfo)

Method body to be executed asynchronously after an application command execution.

public virtual Task AfterExecuteAsync(ICommandInfo command)

Parameters

command ICommandInfo

Command information related to the Discord Application Command.

Returns

Task

BeforeExecute(ICommandInfo)

Method body to be executed before executing an application command.

public virtual void BeforeExecute(ICommandInfo command)

Parameters

command ICommandInfo

Command information related to the Discord Application Command.

BeforeExecuteAsync(ICommandInfo)

Method body to be executed asynchronously before executing an application command.

public virtual Task BeforeExecuteAsync(ICommandInfo command)

Parameters

command ICommandInfo

Command information related to the Discord Application Command.

Returns

Task

Construct(ModuleBuilder, InteractionService)

Method body to be executed after the automated module creation is completed and before Build(InteractionService, IServiceProvider, ModuleInfo) is called.

public virtual void Construct(ModuleBuilder builder, InteractionService commandService)

Parameters

builder ModuleBuilder

Builder class of this module.

commandService InteractionService

Command Service instance that is building this method.

DeferAsync(bool, RequestOptions)

Acknowledges this interaction.

protected virtual Task DeferAsync(bool ephemeral = false, RequestOptions options = null)

Parameters

ephemeral bool
options RequestOptions

Returns

Task

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

DeleteOriginalResponseAsync()

Deletes this object and all its children.

protected virtual Task DeleteOriginalResponseAsync()

Returns

Task

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

Sends a followup message for this interaction.

protected virtual Task<IUserMessage> FollowupAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent components = null, Embed embed = 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.

options RequestOptions

The request options 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.

Returns

Task<IUserMessage>

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

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

Sends a followup message for this interaction.

protected virtual Task<IUserMessage> 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<IUserMessage>

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.

protected virtual Task<IUserMessage> 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<IUserMessage>

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

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

Sends a followup message for this interaction.

protected virtual Task<IUserMessage> 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<IUserMessage>

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

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

Sends a followup message for this interaction.

protected virtual Task<IUserMessage> 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<IUserMessage>

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

GetOriginalResponseAsync(RequestOptions)

Gets the original response for this interaction.

protected virtual Task<IUserMessage> GetOriginalResponseAsync(RequestOptions options = null)

Parameters

options RequestOptions

The request options for this async request.

Returns

Task<IUserMessage>

A IUserMessage that represents the initial response.

ModifyOriginalResponseAsync(Action<MessageProperties>, RequestOptions)

Edits original response for this interaction.

protected virtual Task<IUserMessage> 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<IUserMessage>

A task that represents an asynchronous modification operation. The task result contains the updated message.

OnModuleBuilding(InteractionService, ModuleInfo)

Method body to be executed when Build(InteractionService, IServiceProvider, ModuleInfo) is called.

public virtual void OnModuleBuilding(InteractionService commandService, ModuleInfo module)

Parameters

commandService InteractionService

Command Service instance that built this module.

module ModuleInfo

Info class of this module.

ReplyAsync(string, bool, Embed, RequestOptions, AllowedMentions, MessageReference, MessageComponent, ISticker[], Embed[], MessageFlags)

Sends a message to this message channel.

protected virtual Task<IUserMessage> ReplyAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None)

Parameters

text string

The message to be sent.

isTTS bool

Determines whether the message should be read aloud by Discord or not.

embed Embed

The RichEmbed to be sent.

options RequestOptions

The options to be used when sending the request.

allowedMentions AllowedMentions

Specifies if notifications are sent for mentioned users and roles in the message text. If null, all mentioned roles and users will be notified.

messageReference MessageReference

The message references to be included. Used to reply to specific messages.

components MessageComponent

The message components to be included with this message. Used for interactions.

stickers ISticker[]

A collection of stickers to send with the message.

embeds Embed[]

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

flags MessageFlags

A message flag to be applied to the sent message, only SuppressEmbeds and SuppressNotification is permitted.

Returns

Task<IUserMessage>

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

Examples

The following example sends a message with the current system time in RFC 1123 format to the channel and deletes itself after 5 seconds.

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

Responds to an Interaction with type ChannelMessageWithSource.

protected virtual Task RespondAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent components = null, Embed embed = 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.

options RequestOptions

The request options 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.

Returns

Task

A task that represents an asynchronous send operation for delivering the message.

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

Responds to this interaction with a file attachment.

protected virtual 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.

protected virtual 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.

protected virtual 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.

protected virtual 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 the interaction with a modal.

protected virtual 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.

RespondWithModalAsync<TModal>(string, RequestOptions, Action<ModalBuilder>)

Respond to an interaction with a IModal.

protected virtual Task RespondWithModalAsync<TModal>(string customId, RequestOptions options = null, Action<ModalBuilder> modifyModal = null) where TModal : class, IModal

Parameters

customId string
options RequestOptions

The request options for this async request.

modifyModal Action<ModalBuilder>

Delegate that can be used to modify the modal.

Returns

Task

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

Type Parameters

TModal

RespondWithModalAsync<TModal>(string, TModal, RequestOptions, Action<ModalBuilder>)

Respond to an interaction with an IModal and fills the value fields of the modal using the property values of the provided instance.

protected virtual Task RespondWithModalAsync<TModal>(string customId, TModal modal, RequestOptions options = null, Action<ModalBuilder> modifyModal = null) where TModal : class, IModal

Parameters

customId string
modal TModal

The IModal instance to get field values from.

options RequestOptions

The request options for this async request.

modifyModal Action<ModalBuilder>

Delegate that can be used to modify the modal.

Returns

Task

Type Parameters

TModal

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.

protected virtual Task RespondWithPremiumRequiredAsync(RequestOptions options = null)

Parameters

options RequestOptions

Returns

Task

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