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
ICommandInfoCommand 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
ICommandInfoCommand 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
command
ICommandInfoCommand 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
ICommandInfoCommand 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
builder
ModuleBuilderBuilder class of this module.
commandService
InteractionServiceCommand 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
booloptions
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
FollowupAsync(string, Embed[], bool, bool, AllowedMentions, RequestOptions, MessageComponent, Embed, PollProperties)
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)
Parameters
text
stringThe text of the message to be sent.
embeds
Embed[]A array of embeds to send with this response. Max 10.
isTTS
booltrue if the message should be read out by a text-to-speech reader, otherwise false.
ephemeral
booltrue if the response should be hidden to everyone besides the invoker of the command, otherwise false.
allowedMentions
AllowedMentionsThe allowed mentions for this response.
options
RequestOptionsThe request options for this response.
components
MessageComponentA MessageComponent to be sent with this response.
embed
EmbedA single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.
poll
PollPropertiesA 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.
FollowupWithFileAsync(FileAttachment, string, Embed[], bool, bool, AllowedMentions, MessageComponent, Embed, RequestOptions, PollProperties)
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)
Parameters
attachment
FileAttachmentThe attachment containing the file and description.
text
stringThe text of the message to be sent.
embeds
Embed[]A array of embeds to send with this response. Max 10.
isTTS
booltrue if the message should be read out by a text-to-speech reader, otherwise false.
ephemeral
booltrue if the response should be hidden to everyone besides the invoker of the command, otherwise false.
allowedMentions
AllowedMentionsThe allowed mentions for this response.
components
MessageComponentA MessageComponent to be sent with this response.
embed
EmbedA single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.
options
RequestOptionsThe request options for this response.
poll
PollPropertiesA 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.
FollowupWithFileAsync(Stream, string, string, Embed[], bool, bool, AllowedMentions, MessageComponent, Embed, RequestOptions, PollProperties)
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)
Parameters
fileStream
StreamThe file to upload.
fileName
stringThe file name of the attachment.
text
stringThe text of the message to be sent.
embeds
Embed[]A array of embeds to send with this response. Max 10.
isTTS
booltrue if the message should be read out by a text-to-speech reader, otherwise false.
ephemeral
booltrue if the response should be hidden to everyone besides the invoker of the command, otherwise false.
allowedMentions
AllowedMentionsThe allowed mentions for this response.
components
MessageComponentA MessageComponent to be sent with this response.
embed
EmbedA single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.
options
RequestOptionsThe request options for this response.
poll
PollPropertiesA 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.
FollowupWithFileAsync(string, string, string, Embed[], bool, bool, AllowedMentions, MessageComponent, Embed, RequestOptions, PollProperties)
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)
Parameters
filePath
stringThe file to upload.
fileName
stringThe file name of the attachment.
text
stringThe text of the message to be sent.
embeds
Embed[]A array of embeds to send with this response. Max 10.
isTTS
booltrue if the message should be read out by a text-to-speech reader, otherwise false.
ephemeral
booltrue if the response should be hidden to everyone besides the invoker of the command, otherwise false.
allowedMentions
AllowedMentionsThe allowed mentions for this response.
components
MessageComponentA MessageComponent to be sent with this response.
embed
EmbedA single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.
options
RequestOptionsThe request options for this response.
poll
PollPropertiesA 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.
FollowupWithFilesAsync(IEnumerable<FileAttachment>, string, Embed[], bool, bool, AllowedMentions, MessageComponent, Embed, RequestOptions, PollProperties)
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)
Parameters
attachments
IEnumerable<FileAttachment>A collection of attachments to upload.
text
stringThe text of the message to be sent.
embeds
Embed[]A array of embeds to send with this response. Max 10.
isTTS
booltrue if the message should be read out by a text-to-speech reader, otherwise false.
ephemeral
booltrue if the response should be hidden to everyone besides the invoker of the command, otherwise false.
allowedMentions
AllowedMentionsThe allowed mentions for this response.
components
MessageComponentA MessageComponent to be sent with this response.
embed
EmbedA single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.
options
RequestOptionsThe request options for this response.
poll
PollPropertiesA 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.
GetOriginalResponseAsync(RequestOptions)
Gets the original response for this interaction.
protected virtual Task<IUserMessage> GetOriginalResponseAsync(RequestOptions options = null)
Parameters
options
RequestOptionsThe 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
RequestOptionsThe 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
InteractionServiceCommand Service instance that built this module.
module
ModuleInfoInfo 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
text
stringThe message to be sent.
isTTS
boolDetermines whether the message should be read aloud by Discord or not.
embed
Embedoptions
RequestOptionsThe options to be used when sending the request.
allowedMentions
AllowedMentionsSpecifies if notifications are sent for mentioned users and roles in the message
text
. If null, all mentioned roles and users will be notified.messageReference
MessageReferenceThe message references to be included. Used to reply to specific messages.
components
MessageComponentThe 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
MessageFlagsA message flag to be applied to the sent message, only SuppressEmbeds and SuppressNotification is permitted.
poll
PollPropertiesA 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)
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)
Parameters
text
stringThe text of the message to be sent.
embeds
Embed[]A array of embeds to send with this response. Max 10.
isTTS
booltrue if the message should be read out by a text-to-speech reader, otherwise false.
ephemeral
booltrue if the response should be hidden to everyone besides the invoker of the command, otherwise false.
allowedMentions
AllowedMentionsThe allowed mentions for this response.
options
RequestOptionsThe request options for this response.
components
MessageComponentA MessageComponent to be sent with this response.
embed
EmbedA single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.
poll
PollPropertiesA poll to send with the message.
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)
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)
Parameters
attachment
FileAttachmentThe attachment containing the file and description.
text
stringThe text of the message to be sent.
embeds
Embed[]A array of embeds to send with this response. Max 10.
isTTS
booltrue if the message should be read out by a text-to-speech reader, otherwise false.
ephemeral
booltrue if the response should be hidden to everyone besides the invoker of the command, otherwise false.
allowedMentions
AllowedMentionsThe allowed mentions for this response.
components
MessageComponentA MessageComponent to be sent with this response.
embed
EmbedA single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.
options
RequestOptionsThe request options for this response.
poll
PollPropertiesA poll to send with the message.
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)
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)
Parameters
fileStream
StreamThe file to upload.
fileName
stringThe file name of the attachment.
text
stringThe text of the message to be sent.
embeds
Embed[]A array of embeds to send with this response. Max 10.
isTTS
booltrue if the message should be read out by a text-to-speech reader, otherwise false.
ephemeral
booltrue if the response should be hidden to everyone besides the invoker of the command, otherwise false.
allowedMentions
AllowedMentionsThe allowed mentions for this response.
components
MessageComponentA MessageComponent to be sent with this response.
embed
EmbedA single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.
options
RequestOptionsThe request options for this response.
poll
PollPropertiesA poll to send with the message.
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)
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)
Parameters
filePath
stringThe file to upload.
fileName
stringThe file name of the attachment.
text
stringThe text of the message to be sent.
embeds
Embed[]A array of embeds to send with this response. Max 10.
isTTS
booltrue if the message should be read out by a text-to-speech reader, otherwise false.
ephemeral
booltrue if the response should be hidden to everyone besides the invoker of the command, otherwise false.
allowedMentions
AllowedMentionsThe allowed mentions for this response.
components
MessageComponentA MessageComponent to be sent with this response.
embed
EmbedA single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.
options
RequestOptionsThe request options for this response.
poll
PollPropertiesA poll to send with the message.
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)
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)
Parameters
attachments
IEnumerable<FileAttachment>A collection of attachments to upload.
text
stringThe text of the message to be sent.
embeds
Embed[]A array of embeds to send with this response. Max 10.
isTTS
booltrue if the message should be read out by a text-to-speech reader, otherwise false.
ephemeral
booltrue if the response should be hidden to everyone besides the invoker of the command, otherwise false.
allowedMentions
AllowedMentionsThe allowed mentions for this response.
components
MessageComponentA MessageComponent to be sent with this response.
embed
EmbedA single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.
options
RequestOptionsThe request options for this response.
poll
PollPropertiesA poll to send with the message.
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
ModalThe modal to respond with.
options
RequestOptionsThe 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
stringoptions
RequestOptionsThe 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
stringmodal
TModalThe IModal instance to get field values from.
options
RequestOptionsThe request options for this async request.
modifyModal
Action<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
options
RequestOptions
Returns
- Task
A task that represents the asynchronous operation of responding to the interaction.