Discord.Net.Commands
Marks the aliases for a command.
This attribute allows a command to have one or multiple aliases. In other words, the base command can have
multiple aliases when triggering the command itself, giving the end-user more freedom of choices when giving
hot-words to trigger the desired command. See the example for a better illustration.
In the following example, the command can be triggered with the base name, "stats", or either "stat" or
"info".
[Command("stats")]
[Alias("stat", "info")]
public async Task GetStatsAsync(IUser user)
{
// ...pull stats
}
Gets the aliases which have been defined for the command.
Creates a new with the given aliases.
Marks the execution information for a command.
Gets the text that has been set to be recognized as a command.
Specifies the of the command. This affects how the command is executed.
Initializes a new attribute with the specified name.
The name of the command.
Prevents the marked module from being loaded automatically.
This attribute tells to ignore the marked module from being loaded
automatically (e.g. the method). If a non-public module marked
with this attribute is attempted to be loaded manually, the loading process will also fail.
Prevents the marked property from being injected into a module.
This attribute prevents the marked member from being injected into its parent module. Useful when you have a
public property that you do not wish to invoke the library's dependency injection service.
In the following example, DatabaseService will not be automatically injected into the module and will
not throw an error message if the dependency fails to be resolved.
public class MyModule : ModuleBase
{
[DontInject]
public DatabaseService DatabaseService;
public MyModule()
{
DatabaseService = DatabaseFactory.Generate();
}
}
Marks the module as a command group.
Gets the prefix set for the module.
Initializes a new with the provided prefix.
The prefix of the module group.
Marks the public name of a command, module, or parameter.
Gets the name of the command.
Marks the public name of a command, module, or parameter with the provided name.
The public name of the object.
Instructs the command system to treat command parameters of this type
as a collection of named arguments matching to its properties.
Marks the to be read by the specified .
This attribute will override the to be used when parsing for the
desired type in the command. This is useful when one wishes to use a particular
without affecting other commands that are using the same target
type.
If the given type reader does not inherit from , an
will be thrown.
In this example, the will be read by a custom
, FriendlyTimeSpanTypeReader, instead of the
shipped by Discord.Net.
[Command("time")]
public Task GetTimeAsync([OverrideTypeReader(typeof(FriendlyTimeSpanTypeReader))]TimeSpan time)
=> ReplyAsync(time);
Gets the specified of the parameter.
The to be used with the parameter.
The given does not inherit from .
Requires the parameter to pass the specified precondition before execution can begin.
Checks whether the condition is met before execution of the command.
The context of the command.
The parameter of the command being checked against.
The raw value of the parameter.
The service collection used for dependency injection.
Requires the module or class to pass the specified precondition before execution can begin.
Specifies a group that this precondition belongs to.
of the same group require only one of the preconditions to pass in order to
be successful (A || B). Specifying = null or not at all will
require *all* preconditions to pass, just like normal (A && B).
When overridden in a derived class, uses the supplied string
as the error message if the precondition doesn't pass.
Setting this for a class that doesn't override
this property is a no-op.
Checks if the has the sufficient permission to be executed.
The context of the command.
The command being executed.
The service collection used for dependency injection.
Requires the bot to have a specific permission in the channel a command is invoked in.
Gets the specified of the precondition.
Gets the specified of the precondition.
Gets or sets the error message if the precondition
fails due to being run outside of a Guild channel.
Requires the bot account to have a specific .
This precondition will always fail if the command is being invoked in a .
The that the bot must have. Multiple permissions can be specified
by ORing the permissions together.
Requires that the bot account to have a specific .
The that the bot must have. Multiple permissions can be
specified by ORing the permissions together.
Defines the type of command context (i.e. where the command is being executed).
Specifies the command to be executed within a guild.
Specifies the command to be executed within a DM.
Specifies the command to be executed within a group.
Requires the command to be invoked in a specified context (e.g. in guild, DM).
Gets the context required to execute the command.
Requires the command to be invoked in the specified context.
The type of context the command can be invoked in. Multiple contexts can be specified by ORing the contexts together.
[Command("secret")]
[RequireContext(ContextType.DM | ContextType.Group)]
public Task PrivateOnlyAsync()
{
return ReplyAsync("shh, this command is a secret");
}
Requires the command to be invoked in a channel marked NSFW.
The precondition will restrict the access of the command or module to be accessed within a guild channel
that has been marked as mature or NSFW. If the channel is not of type or the
channel is not marked as NSFW, the precondition will fail with an erroneous .
The following example restricts the command too-cool to an NSFW-enabled channel only.
public class DankModule : ModuleBase
{
[Command("cool")]
public Task CoolAsync()
=> ReplyAsync("I'm cool for everyone.");
[RequireNsfw]
[Command("too-cool")]
public Task TooCoolAsync()
=> ReplyAsync("You can only see this if you're cool enough.");
}
Requires the command to be invoked by the owner of the bot.
This precondition will restrict the access of the command or module to the owner of the Discord application.
If the precondition fails to be met, an erroneous will be returned with the
message "Command can only be run by the owner of the bot."
This precondition will only work if the account has a of
;otherwise, this precondition will always fail.
The following example restricts the command to a set of sensitive commands that only the owner of the bot
application should be able to access.
[RequireOwner]
[Group("admin")]
public class AdminModule : ModuleBase
{
[Command("exit")]
public async Task ExitAsync()
{
Environment.Exit(0);
}
}
Requires the user invoking the command to have a specified permission.
Gets the specified of the precondition.
Gets the specified of the precondition.
Gets or sets the error message if the precondition
fails due to being run outside of a Guild channel.
Requires that the user invoking the command to have a specific .
This precondition will always fail if the command is being invoked in a .
The that the user must have. Multiple permissions can be
specified by ORing the permissions together.
Requires that the user invoking the command to have a specific .
The that the user must have. Multiple permissions can be
specified by ORing the permissions together.
Sets priority of commands.
Gets the priority which has been set for the command.
Initializes a new attribute with the given priority.
Marks the input to not be parsed by the parser.
Attaches remarks to your commands.
Attaches a summary to your command.
Only the last parameter in a command may have the Remainder or Multiple flag.
The context of a command which may contain the client, user, guild, channel, and message.
Indicates whether the channel that the command is executed in is a private channel.
Initializes a new class with the provided client and message.
The underlying client.
The underlying message.
Defines the type of error a command can throw.
Thrown when the command is unknown.
Thrown when the command fails to be parsed.
Thrown when the input text has too few or too many arguments.
Thrown when the object cannot be found by the .
Thrown when more than one object is matched by .
Thrown when the command fails to meet a 's conditions.
Thrown when an exception occurs mid-command execution.
Thrown when the command is not successfully executed on runtime.
The exception that is thrown if another exception occurs during a command execution.
Gets the command that caused the exception.
Gets the command context of the exception.
Initializes a new instance of the class using a
information, a context, and the exception that
interrupted the execution.
The command information.
The context of the command.
The exception that interrupted the command execution.
The command that matches the search result.
The alias of the command.
Provides a framework for building Discord commands.
The service provides a framework for building Discord commands both dynamically via runtime builders or
statically via compile-time modules. To create a command module at compile-time, see
(most common); otherwise, see .
This service also provides several events for monitoring command usages; such as
for any command-related log events, and
for information about commands that have
been successfully executed.
Occurs when a command-related information is received.
Occurs when a command is executed.
This event is fired when a command has been executed, successfully or not. When a command fails to
execute during parsing or precondition stage, the CommandInfo may not be returned.
Represents all modules loaded within .
Represents all commands loaded within .
Represents all loaded within .
Initializes a new class.
Initializes a new class with the provided configuration.
The configuration class.
The cannot be set to .
Add a command module from a .
The following example registers the module MyModule to commandService.
await commandService.AddModuleAsync<MyModule>(serviceProvider);
The type of module.
The for your dependency injection solution if using one; otherwise, pass null.
This module has already been added.
The fails to be built; an invalid type may have been provided.
A task that represents the asynchronous operation for adding the module. The task result contains the
built module.
Adds a command module from a .
The type of module.
The for your dependency injection solution if using one; otherwise, pass null .
This module has already been added.
The fails to be built; an invalid type may have been provided.
A task that represents the asynchronous operation for adding the module. The task result contains the
built module.
Add command modules from an .
The containing command modules.
The for your dependency injection solution if using one; otherwise, pass null.
A task that represents the asynchronous operation for adding the command modules. The task result
contains an enumerable collection of modules added.
Removes the command module.
The to be removed from the service.
A task that represents the asynchronous removal operation. The task result contains a value that
indicates whether the is successfully removed.
Removes the command module.
The of the module.
A task that represents the asynchronous removal operation. The task result contains a value that
indicates whether the module is successfully removed.
Removes the command module.
The of the module.
A task that represents the asynchronous removal operation. The task result contains a value that
indicates whether the module is successfully removed.
Adds a custom to this for the supplied object
type.
If is a , a nullable will
also be added.
If a default exists for , a warning will be logged
and the default will be replaced.
The object type to be read by the .
An instance of the to be added.
Adds a custom to this for the supplied object
type.
If is a , a nullable for the
value type will also be added.
If a default exists for , a warning will be logged and
the default will be replaced.
A instance for the type to be read.
An instance of the to be added.
Adds a custom to this for the supplied object
type.
If is a , a nullable will
also be added.
The object type to be read by the .
An instance of the to be added.
Defines whether the should replace the default one for
if it exists.
Adds a custom to this for the supplied object
type.
If is a , a nullable for the
value type will also be added.
A instance for the type to be read.
An instance of the to be added.
Defines whether the should replace the default one for if
it exists.
Searches for the command.
The context of the command.
The position of which the command starts at.
The result containing the matching commands.
Searches for the command.
The context of the command.
The command string.
The result containing the matching commands.
Executes the command.
The context of the command.
The position of which the command starts at.
The service to be used in the command's dependency injection.
The handling mode when multiple command matches are found.
A task that represents the asynchronous execution operation. The task result contains the result of the
command execution.
Executes the command.
The context of the command.
The command string.
The service to be used in the command's dependency injection.
The handling mode when multiple command matches are found.
A task that represents the asynchronous execution operation. The task result contains the result of the
command execution.
Represents a configuration class for .
Gets or sets the default commands should have, if one is not specified on the
Command attribute or builder.
Gets or sets the that separates an argument with another.
Gets or sets whether commands should be case-sensitive.
Gets or sets the minimum log level severity that will be sent to the event.
Gets or sets whether commands should push exceptions up to the caller.
Collection of aliases for matching pairs of string delimiters.
The dictionary stores the opening delimiter as a key, and the matching closing delimiter as the value.
If no value is supplied will be used, which contains
many regional equivalents.
Only values that are specified in this map will be used as string delimiters, so if " is removed then
it won't be used.
If this map is set to null or empty, the default delimiter of " will be used.
QuotationMarkAliasMap = new Dictionary<char, char>()
{
{'\"', '\"' },
{'“', '”' },
{'「', '」' },
}
Gets or sets a value that indicates whether extra parameters should be ignored.
Provides extension methods for the class.
Returns commands that can be executed under the current context.
The set of commands to be checked against.
The current command context.
The service provider used for dependency injection upon precondition check.
A read-only collection of commands that can be executed under the current context.
Returns commands that can be executed under the current context.
The desired command service class to check against.
The current command context.
The service provider used for dependency injection upon precondition check.
A read-only collection of commands that can be executed under the current context.
Returns commands that can be executed under the current context.
The module to be checked against.
The current command context.
The service provider used for dependency injection upon precondition check.
A read-only collection of commands that can be executed under the current context.
Provides extension methods for that relates to commands.
Gets whether the message starts with the provided character.
The message to check against.
The char prefix.
References where the command starts.
true if the message begins with the char ; otherwise false.
Gets whether the message starts with the provided string.
Gets whether the message starts with the user's mention string.
Provides the information of a command.
This object contains the information of a command. This can include the module of the command, various
descriptions regarding the command, and its .
Gets the module that the command belongs in.
Gets the name of the command. If none is set, the first alias is used.
Gets the summary of the command.
This field returns the summary of the command. and can be
useful in help commands and various implementation that fetches details of the command for the user.
Gets the remarks of the command.
This field returns the summary of the command. and can be
useful in help commands and various implementation that fetches details of the command for the user.
Gets the priority of the command. This is used when there are multiple overloads of the command.
Indicates whether the command accepts a [] for its
parameter.
Indicates whether extra arguments should be ignored for this command.
Gets the that is being used for the command.
Gets a list of aliases defined by the of the command.
Gets a list of information about the parameters of the command.
Gets a list of preconditions defined by the of the command.
Gets a list of attributes of the command.
Provides the information of a module.
Gets the command service associated with this module.
Gets the name of this module.
Gets the summary of this module.
Gets the remarks of this module.
Gets the group name (main prefix) of this module.
Gets a read-only list of aliases associated with this module.
Gets a read-only list of commands associated with this module.
Gets a read-only list of preconditions that apply to this module.
Gets a read-only list of attributes that apply to this module.
Gets a read-only list of submodules associated with this module.
Gets the parent module of this submodule if applicable.
Gets a value that indicates whether this module is a submodule or not.
Provides the information of a parameter.
Gets the command that associates with this parameter.
Gets the name of this parameter.
Gets the summary of this parameter.
Gets a value that indicates whether this parameter is optional or not.
Gets a value that indicates whether this parameter is a remainder parameter or not.
Gets the type of the parameter.
Gets the default value for this optional parameter if applicable.
Gets a read-only list of precondition that apply to this parameter.
Gets a read-only list of attributes that apply to this parameter.
Cannot add commands to the root node.
Provides a base class for a command module to inherit from.
Provides a base class for a command module to inherit from.
A class that implements .
The underlying context of the command.
Sends a message to the source channel.
Contents of the message; optional only if is specified.
Specifies if Discord should read this aloud using text-to-speech.
An embed to be displayed alongside the .
Specifies if notifications are sent for mentioned users and roles in the .
If null, all mentioned roles and users will be notified.
The request options for this async request.
The message references to be included. Used to reply to specific messages.
The message components to be included with this message. Used for interactions.
A collection of stickers to send with the file.
A array of s to send with this response. Max 10.
The method to execute before executing the command.
The of the command to be executed.
The method to execute after executing the command.
The of the command to be executed.
The method to execute when building the module.
The used to create the module.
The builder used to build the module.
Specifies the behavior when multiple matches are found during the command parsing stage.
Indicates that when multiple results are found, an exception should be thrown.
Indicates that when multiple results are found, the best result should be chosen.
A for parsing objects implementing .
This is shipped with Discord.Net and is used by default to parse any
implemented object within a command. The TypeReader will attempt to first parse the
input by mention, then the snowflake identifier, then by name; the highest candidate will be chosen as the
final output; otherwise, an erroneous is returned.
The type to be checked; must implement .
A for parsing objects implementing .
The type to be checked; must implement .
must be within the range [0, 1].
must be within the range [0, 1].
A for parsing objects implementing .
The type to be checked; must implement .
Defines a reader class that parses user input into a specified type.
Attempts to parse the into the desired type.
The context of the command.
The raw input of the command.
The service collection used for dependency injection.
A task that represents the asynchronous parsing operation. The task result contains the parsing result.
A for parsing objects implementing .
The type to be checked; must implement .
Contains information of the command's overall execution result.
Gets the exception that may have occurred during the command execution.
Initializes a new with no error, indicating a successful execution.
A that does not contain any errors.
Initializes a new with a specified and its
reason, indicating an unsuccessful execution.
The type of error.
The reason behind the error.
A that contains a and reason.
Initializes a new with a specified exception, indicating an unsuccessful
execution.
The exception that caused the command execution to fail.
A that contains the exception that caused the unsuccessful execution, along
with a of type Exception as well as the exception message as the
reason.
Initializes a new with a specified result; this may or may not be an
successful execution depending on the and
specified.
The result to inherit from.
A that inherits the error type and reason.
Gets a string that indicates the execution result.
Success if is true; otherwise ":
".
Contains information of the result related to a command.
Describes the error type that may have occurred during the operation.
A indicating the type of error that may have occurred during the operation;
null if the operation was successful.
Describes the reason for the error.
A string containing the error reason.
Indicates whether the operation was successful or not.
true if the result is positive; otherwise false.
Contains information for the parsing result from the command service's parser.
Provides information about the parameter that caused the parsing error.
A indicating the parameter info of the error that may have occurred during parsing;
null if the parsing was successful or the parsing error is not specific to a single parameter.
Represents a result type for command preconditions.
Initializes a new class with the command type
and reason.
The type of failure.
The reason of failure.
Returns a with no errors.
Returns a with and the
specified reason.
The reason of failure.
Returns a with the specified type.
The result of failure.
Returns a string indicating whether the is successful.
Initializes a new class with the type of error and reason.
The type of failure, or null if none.
The reason of failure.
Describes the execution reason or result.
TypeReaderResult was not successful.
Specifies the behavior of the command execution workflow.
The default behaviour set in .
Executes the command on the same thread as gateway one.
Executes the command on a different thread from the gateway one.
Utility class which contains the default matching pairs of quotation marks for CommandServiceConfig
A default map of open-close pairs of quotation marks.
Contains many regional and Unicode equivalents.
Used in the .