Class CommandService
Provides a framework for building Discord commands.
Assembly: Discord.Net.Commands.dll​
View Source​
public class CommandService : IDisposable
Properties​
Modules​
Represents all modules loaded within Discord.Commands.CommandService.
View Source​
public IEnumerable<ModuleInfo> Modules { get; }
Commands​
Represents all commands loaded within Discord.Commands.CommandService.
View Source​
public IEnumerable<CommandInfo> Commands { get; }
TypeReaders​
Represents all Discord.Commands.TypeReader loaded within Discord.Commands.CommandService.
View Source​
public ILookup<Type, TypeReader> TypeReaders { get; }
Methods​
CreateModuleAsync(String, Action<ModuleBuilder>)​
View Source​
public async Task<ModuleInfo> CreateModuleAsync(string primaryAlias, Action<ModuleBuilder> buildFunc)
Returns​
System.Threading.Tasks.Task<Discord.Commands.ModuleInfo>
Parameters​
Type | Name |
---|---|
System.String | primaryAlias |
System.Action<Discord.Commands.Builders.ModuleBuilder> | buildFunc |
AddModuleAsync<T>(IServiceProvider)​
Add a command module from a System.Type
.
View Source​
public Task<ModuleInfo> AddModuleAsync<T>(IServiceProvider services)
Returns​
System.Threading.Tasks.Task<Discord.Commands.ModuleInfo>
:
A task that represents the asynchronous operation for adding the module. The task result contains the
built module.
Parameters​
Type | Name | Description |
---|---|---|
System.IServiceProvider | services | The System.IServiceProvider for your dependency injection solution if using one; otherwise, pass null . |
Type Parameters​
Name | Description |
---|---|
T | The type of module. |
AddModuleAsync(Type, IServiceProvider)​
Adds a command module from a System.Type
.
View Source​
public async Task<ModuleInfo> AddModuleAsync(Type type, IServiceProvider services)
Returns​
System.Threading.Tasks.Task<Discord.Commands.ModuleInfo>
:
A task that represents the asynchronous operation for adding the module. The task result contains the
built module.
Parameters​
Type | Name | Description |
---|---|---|
System.Type | type | The type of module. |
System.IServiceProvider | services | The System.IServiceProvider for your dependency injection solution if using one; otherwise, pass null . |
AddModulesAsync(Assembly, IServiceProvider)​
Add command modules from an System.Reflection.Assembly
.
View Source​
public async Task<IEnumerable<ModuleInfo>> AddModulesAsync(Assembly assembly, IServiceProvider services)
Returns​
System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Discord.Commands.ModuleInfo>>
:
A task that represents the asynchronous operation for adding the command modules. The task result
contains an enumerable collection of modules added.
Parameters​
Type | Name | Description |
---|---|---|
System.Reflection.Assembly | assembly | The System.Reflection.Assembly containing command modules. |
System.IServiceProvider | services | The System.IServiceProvider for your dependency injection solution if using one; otherwise, pass null . |
RemoveModuleAsync(ModuleInfo)​
Removes the command module.
View Source​
public async Task<bool> RemoveModuleAsync(ModuleInfo module)
Returns​
System.Threading.Tasks.Task<System.Boolean>
:
A task that represents the asynchronous removal operation. The task result contains a value that
indicates whether the <code data-dev-comment-type="paramref" class="paramref">module</code> is successfully removed.
Parameters​
Type | Name | Description |
---|---|---|
Discord.Commands.ModuleInfo | module | The Discord.Commands.ModuleInfo to be removed from the service. |
RemoveModuleAsync<T>()​
Removes the command module.
View Source​
public Task<bool> RemoveModuleAsync<T>()
Returns​
System.Threading.Tasks.Task<System.Boolean>
:
A task that represents the asynchronous removal operation. The task result contains a value that
indicates whether the module is successfully removed.
Type Parameters​
Name | Description |
---|---|
T | The |
RemoveModuleAsync(Type)​
Removes the command module.
View Source​
public async Task<bool> RemoveModuleAsync(Type type)
Returns​
System.Threading.Tasks.Task<System.Boolean>
:
A task that represents the asynchronous removal operation. The task result contains a value that
indicates whether the module is successfully removed.
Parameters​
Type | Name | Description |
---|---|---|
System.Type | type | The System.Type of the module. |
AddTypeReader<T>(TypeReader)​
Adds a custom Discord.Commands.TypeReader to this Discord.Commands.CommandService for the supplied object
type.
If <code data-dev-comment-type="typeparamref" class="typeparamref">T</code> is a System.ValueType
, a nullable Discord.Commands.TypeReader will
also be added.
If a default Discord.Commands.TypeReader exists for <code data-dev-comment-type="typeparamref" class="typeparamref">T</code>, a warning will be logged
and the default Discord.Commands.TypeReader will be replaced.
View Source​
public void AddTypeReader<T>(TypeReader reader)
Parameters​
Type | Name | Description |
---|---|---|
Discord.Commands.TypeReader | reader | An instance of the Discord.Commands.TypeReader to be added. |
Type Parameters​
Name | Description |
---|---|
T | The object type to be read by the |
AddTypeReader(Type, TypeReader)​
Adds a custom Discord.Commands.TypeReader to this Discord.Commands.CommandService for the supplied object
type.
If <code data-dev-comment-type="paramref" class="paramref">type</code> is a System.ValueType
, a nullable Discord.Commands.TypeReader for the
value type will also be added.
If a default Discord.Commands.TypeReader exists for <code data-dev-comment-type="paramref" class="paramref">type</code>, a warning will be logged and
the default Discord.Commands.TypeReader will be replaced.
View Source​
public void AddTypeReader(Type type, TypeReader reader)
Parameters​
Type | Name | Description |
---|---|---|
System.Type | type | A System.Type instance for the type to be read. |
Discord.Commands.TypeReader | reader | An instance of the Discord.Commands.TypeReader to be added. |
AddTypeReader<T>(TypeReader, Boolean)​
Adds a custom Discord.Commands.TypeReader to this Discord.Commands.CommandService for the supplied object
type.
If <code data-dev-comment-type="typeparamref" class="typeparamref">T</code> is a System.ValueType
, a nullable Discord.Commands.TypeReader will
also be added.
View Source​
public void AddTypeReader<T>(TypeReader reader, bool replaceDefault)
Parameters​
Type | Name | Description |
---|---|---|
Discord.Commands.TypeReader | reader | An instance of the Discord.Commands.TypeReader to be added. |
System.Boolean | replaceDefault |
Defines whether the Discord.Commands.TypeReader should replace the default one for
System.Type
if it exists.
|
Type Parameters​
Name | Description |
---|---|
T | The object type to be read by the |
AddTypeReader(Type, TypeReader, Boolean)​
Adds a custom Discord.Commands.TypeReader to this Discord.Commands.CommandService for the supplied object
type.
If <code data-dev-comment-type="paramref" class="paramref">type</code> is a System.ValueType
, a nullable Discord.Commands.TypeReader for the
value type will also be added.
View Source​
public void AddTypeReader(Type type, TypeReader reader, bool replaceDefault)
Parameters​
Type | Name | Description |
---|---|---|
System.Type | type | A System.Type instance for the type to be read. |
Discord.Commands.TypeReader | reader | An instance of the Discord.Commands.TypeReader to be added. |
System.Boolean | replaceDefault |
Defines whether the Discord.Commands.TypeReader should replace the default one for System.Type
if
it exists.
|
Search(ICommandContext, Int32)​
Searches for the command.
View Source​
public SearchResult Search(ICommandContext context, int argPos)
Returns​
Discord.Commands.SearchResult: The result containing the matching commands.
Parameters​
Type | Name | Description |
---|---|---|
Discord.Commands.ICommandContext | context | The context of the command. |
System.Int32 | argPos | The position of which the command starts at. |
Search(ICommandContext, String)​
Searches for the command.
View Source​
public SearchResult Search(ICommandContext context, string input)
Returns​
Discord.Commands.SearchResult: The result containing the matching commands.
Parameters​
Type | Name | Description |
---|---|---|
Discord.Commands.ICommandContext | context | The context of the command. |
System.String | input | The command string. |
Search(String)​
View Source​
public SearchResult Search(string input)
Returns​
Parameters​
Type | Name |
---|---|
System.String | input |
ExecuteAsync(ICommandContext, Int32, IServiceProvider, MultiMatchHandling)​
Executes the command.
View Source​
public Task<IResult> ExecuteAsync(ICommandContext context, int argPos, IServiceProvider services, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception)
Returns​
System.Threading.Tasks.Task<Discord.Commands.IResult>
:
A task that represents the asynchronous execution operation. The task result contains the result of the
command execution.
Parameters​
Type | Name | Description |
---|---|---|
Discord.Commands.ICommandContext | context | The context of the command. |
System.Int32 | argPos | The position of which the command starts at. |
System.IServiceProvider | services | The service to be used in the command's dependency injection. |
Discord.Commands.MultiMatchHandling | multiMatchHandling | The handling mode when multiple command matches are found. |
ExecuteAsync(ICommandContext, String, IServiceProvider, MultiMatchHandling)​
Executes the command.
View Source​
public async Task<IResult> ExecuteAsync(ICommandContext context, string input, IServiceProvider services, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception)
Returns​
System.Threading.Tasks.Task<Discord.Commands.IResult>
:
A task that represents the asynchronous execution operation. The task result contains the result of the
command execution.
Parameters​
Type | Name | Description |
---|---|---|
Discord.Commands.ICommandContext | context | The context of the command. |
System.String | input | The command string. |
System.IServiceProvider | services | The service to be used in the command's dependency injection. |
Discord.Commands.MultiMatchHandling | multiMatchHandling | The handling mode when multiple command matches are found. |
ValidateAndGetBestMatch(SearchResult, ICommandContext, IServiceProvider, MultiMatchHandling)​
Validates and gets the best Discord.Commands.CommandMatch from a specified Discord.Commands.SearchResult
View Source​
public async Task<IResult> ValidateAndGetBestMatch(SearchResult matches, ICommandContext context, IServiceProvider provider, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception)
Returns​
System.Threading.Tasks.Task<Discord.Commands.IResult>
: A task that represents the asynchronous validation operation. The task result contains the result of the
command validation as a Discord.Commands.MatchResult or a Discord.Commands.SearchResult if no matches were found.
Parameters​
Type | Name | Description |
---|---|---|
Discord.Commands.SearchResult | matches | The SearchResult. |
Discord.Commands.ICommandContext | context | The context of the command. |
System.IServiceProvider | provider | The service provider to be used on the command's dependency injection. |
Discord.Commands.MultiMatchHandling | multiMatchHandling | The handling mode when multiple command matches are found. |
Dispose(Boolean)​
View Source​
protected virtual void Dispose(bool disposing)
Parameters​
Type | Name |
---|---|
System.Boolean | disposing |
IDisposable.Dispose()​
View Source​
void IDisposable.Dispose()
Events​
Log​
Occurs when a command-related information is received.
View Source​
public event Func<LogMessage, Task> Log
Event Type​
System.Func<Discord.LogMessage,System.Threading.Tasks.Task>
CommandExecuted​
Occurs when a command is executed.
View Source​
public event Func<Optional<CommandInfo>, ICommandContext, IResult, Task> CommandExecuted
Event Type​
System.Func<Discord.Optional<Discord.Commands.CommandInfo>,Discord.Commands.ICommandContext,Discord.Commands.IResult,System.Threading.Tasks.Task>
Implements​
System.IDisposable
Extension Methods​
- Discord.Commands.CommandService.Discord.Commands.CommandServiceExtensions.GetExecutableCommandsAsync(Discord.Commands.ICommandContext,System.IServiceProvider)