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
TType 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
commandICommandInfoCommand 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
commandICommandInfoCommand information related to the Discord Application Command.
Returns
BeforeExecute(ICommandInfo)
Method body to be executed before executing an application command.
public virtual void BeforeExecute(ICommandInfo command)
Parameters
commandICommandInfoCommand 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
commandICommandInfoCommand information related to the Discord Application Command.
Returns
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
builderModuleBuilderBuilder class of this module.
commandServiceInteractionServiceCommand Service instance that is building this method.
DeferAsync(bool, RequestOptions)
Acknowledges this interaction.
protected virtual Task DeferAsync(bool ephemeral = false, RequestOptions options = null)
Parameters
ephemeralbooloptionsRequestOptions
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
FollowupAsync(string, Embed[], bool, bool, AllowedMentions, RequestOptions, MessageComponent, Embed, PollProperties, MessageFlags)
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, PollProperties poll = null, MessageFlags flags = MessageFlags.None)
Parameters
textstringThe text of the message to be sent.
embedsEmbed[]A array of embeds to send with this response. Max 10.
isTTSbooltrue if the message should be read out by a text-to-speech reader, otherwise false.
ephemeralbooltrue if the response should be hidden to everyone besides the invoker of the command, otherwise false.
allowedMentionsAllowedMentionsThe allowed mentions for this response.
optionsRequestOptionsThe request options for this response.
componentsMessageComponentA MessageComponent to be sent with this response.
embedEmbedA single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.
pollPollPropertiesA poll to send with the message.
flagsMessageFlags
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, PollProperties, MessageFlags)
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, PollProperties poll = null, MessageFlags flags = MessageFlags.None)
Parameters
attachmentFileAttachmentThe attachment containing the file and description.
textstringThe text of the message to be sent.
embedsEmbed[]A array of embeds to send with this response. Max 10.
isTTSbooltrue if the message should be read out by a text-to-speech reader, otherwise false.
ephemeralbooltrue if the response should be hidden to everyone besides the invoker of the command, otherwise false.
allowedMentionsAllowedMentionsThe allowed mentions for this response.
componentsMessageComponentA MessageComponent to be sent with this response.
embedEmbedA single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.
optionsRequestOptionsThe request options for this response.
pollPollPropertiesA poll to send with the message.
flagsMessageFlags
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, PollProperties, MessageFlags)
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, PollProperties poll = null, MessageFlags flags = MessageFlags.None)
Parameters
fileStreamStreamThe file to upload.
fileNamestringThe file name of the attachment.
textstringThe text of the message to be sent.
embedsEmbed[]A array of embeds to send with this response. Max 10.
isTTSbooltrue if the message should be read out by a text-to-speech reader, otherwise false.
ephemeralbooltrue if the response should be hidden to everyone besides the invoker of the command, otherwise false.
allowedMentionsAllowedMentionsThe allowed mentions for this response.
componentsMessageComponentA MessageComponent to be sent with this response.
embedEmbedA single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.
optionsRequestOptionsThe request options for this response.
pollPollPropertiesA poll to send with the message.
flagsMessageFlags
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, PollProperties, MessageFlags)
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, PollProperties poll = null, MessageFlags flags = MessageFlags.None)
Parameters
filePathstringThe file to upload.
fileNamestringThe file name of the attachment.
textstringThe text of the message to be sent.
embedsEmbed[]A array of embeds to send with this response. Max 10.
isTTSbooltrue if the message should be read out by a text-to-speech reader, otherwise false.
ephemeralbooltrue if the response should be hidden to everyone besides the invoker of the command, otherwise false.
allowedMentionsAllowedMentionsThe allowed mentions for this response.
componentsMessageComponentA MessageComponent to be sent with this response.
embedEmbedA single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.
optionsRequestOptionsThe request options for this response.
pollPollPropertiesA poll to send with the message.
flagsMessageFlags
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, PollProperties, MessageFlags)
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, PollProperties poll = null, MessageFlags flags = MessageFlags.None)
Parameters
attachmentsIEnumerable<FileAttachment>A collection of attachments to upload.
textstringThe text of the message to be sent.
embedsEmbed[]A array of embeds to send with this response. Max 10.
isTTSbooltrue if the message should be read out by a text-to-speech reader, otherwise false.
ephemeralbooltrue if the response should be hidden to everyone besides the invoker of the command, otherwise false.
allowedMentionsAllowedMentionsThe allowed mentions for this response.
componentsMessageComponentA MessageComponent to be sent with this response.
embedEmbedA single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.
optionsRequestOptionsThe request options for this response.
pollPollPropertiesA poll to send with the message.
flagsMessageFlags
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
optionsRequestOptionsThe 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
funcAction<MessageProperties>A delegate containing the properties to modify the message with.
optionsRequestOptionsThe 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
commandServiceInteractionServiceCommand Service instance that built this module.
moduleModuleInfoInfo class of this module.
ReplyAsync(string, bool, Embed, RequestOptions, AllowedMentions, MessageReference, MessageComponent, ISticker[], Embed[], MessageFlags, PollProperties)
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, PollProperties poll = null)
Parameters
textstringThe message to be sent.
isTTSboolDetermines whether the message should be read aloud by Discord or not.
embedEmbedoptionsRequestOptionsThe options to be used when sending the request.
allowedMentionsAllowedMentionsSpecifies if notifications are sent for mentioned users and roles in the message
text. If null, all mentioned roles and users will be notified.messageReferenceMessageReferenceThe message references to be included. Used to reply to specific messages.
componentsMessageComponentThe message components to be included with this message. Used for interactions.
stickersISticker[]A collection of stickers to send with the message.
embedsEmbed[]A array of Embeds to send with this response. Max 10.
flagsMessageFlagsA message flag to be applied to the sent message, only SuppressEmbeds and SuppressNotification is permitted.
pollPollPropertiesA poll to send with the message.
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, PollProperties, MessageFlags)
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, PollProperties poll = null, MessageFlags flags = MessageFlags.None)
Parameters
textstringThe text of the message to be sent.
embedsEmbed[]A array of embeds to send with this response. Max 10.
isTTSbooltrue if the message should be read out by a text-to-speech reader, otherwise false.
ephemeralbooltrue if the response should be hidden to everyone besides the invoker of the command, otherwise false.
allowedMentionsAllowedMentionsThe allowed mentions for this response.
optionsRequestOptionsThe request options for this response.
componentsMessageComponentA MessageComponent to be sent with this response.
embedEmbedA single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.
pollPollPropertiesA poll to send with the message.
flagsMessageFlags
Returns
- Task
A task that represents an asynchronous send operation for delivering the message.
RespondWithFileAsync(FileAttachment, string, Embed[], bool, bool, AllowedMentions, MessageComponent, Embed, RequestOptions, PollProperties, MessageFlags)
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, PollProperties poll = null, MessageFlags flags = MessageFlags.None)
Parameters
attachmentFileAttachmentThe attachment containing the file and description.
textstringThe text of the message to be sent.
embedsEmbed[]A array of embeds to send with this response. Max 10.
isTTSbooltrue if the message should be read out by a text-to-speech reader, otherwise false.
ephemeralbooltrue if the response should be hidden to everyone besides the invoker of the command, otherwise false.
allowedMentionsAllowedMentionsThe allowed mentions for this response.
componentsMessageComponentA MessageComponent to be sent with this response.
embedEmbedA single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.
optionsRequestOptionsThe request options for this response.
pollPollPropertiesA poll to send with the message.
flagsMessageFlags
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, PollProperties, MessageFlags)
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, PollProperties poll = null, MessageFlags flags = MessageFlags.None)
Parameters
fileStreamStreamThe file to upload.
fileNamestringThe file name of the attachment.
textstringThe text of the message to be sent.
embedsEmbed[]A array of embeds to send with this response. Max 10.
isTTSbooltrue if the message should be read out by a text-to-speech reader, otherwise false.
ephemeralbooltrue if the response should be hidden to everyone besides the invoker of the command, otherwise false.
allowedMentionsAllowedMentionsThe allowed mentions for this response.
componentsMessageComponentA MessageComponent to be sent with this response.
embedEmbedA single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.
optionsRequestOptionsThe request options for this response.
pollPollPropertiesA poll to send with the message.
flagsMessageFlags
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, PollProperties, MessageFlags)
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, PollProperties poll = null, MessageFlags flags = MessageFlags.None)
Parameters
filePathstringThe file to upload.
fileNamestringThe file name of the attachment.
textstringThe text of the message to be sent.
embedsEmbed[]A array of embeds to send with this response. Max 10.
isTTSbooltrue if the message should be read out by a text-to-speech reader, otherwise false.
ephemeralbooltrue if the response should be hidden to everyone besides the invoker of the command, otherwise false.
allowedMentionsAllowedMentionsThe allowed mentions for this response.
componentsMessageComponentA MessageComponent to be sent with this response.
embedEmbedA single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.
optionsRequestOptionsThe request options for this response.
pollPollPropertiesA poll to send with the message.
flagsMessageFlags
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, PollProperties, MessageFlags)
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, PollProperties poll = null, MessageFlags flags = MessageFlags.None)
Parameters
attachmentsIEnumerable<FileAttachment>A collection of attachments to upload.
textstringThe text of the message to be sent.
embedsEmbed[]A array of embeds to send with this response. Max 10.
isTTSbooltrue if the message should be read out by a text-to-speech reader, otherwise false.
ephemeralbooltrue if the response should be hidden to everyone besides the invoker of the command, otherwise false.
allowedMentionsAllowedMentionsThe allowed mentions for this response.
componentsMessageComponentA MessageComponent to be sent with this response.
embedEmbedA single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.
optionsRequestOptionsThe request options for this response.
pollPollPropertiesA poll to send with the message.
flagsMessageFlags
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
modalModalThe modal to respond with.
optionsRequestOptionsThe 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
customIdstringoptionsRequestOptionsThe request options for this async request.
modifyModalAction<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
customIdstringmodalTModalThe IModal instance to get field values from.
optionsRequestOptionsThe request options for this async request.
modifyModalAction<ModalBuilder>Delegate that can be used to modify the modal.
Returns
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
optionsRequestOptions
Returns
- Task
A task that represents the asynchronous operation of responding to the interaction.