Class CommandService
Provides a framework for building Discord commands.
Assembly: Revolt.Net.Commands.dll​
View Source​
public class CommandService : IDisposable
Properties​
Modules​
Represents all modules loaded within Revolt.Commands.CommandService.
View Source​
public IEnumerable<ModuleInfo> Modules { get; }
Commands​
Represents all commands loaded within Revolt.Commands.CommandService.
View Source​
public IEnumerable<CommandInfo> Commands { get; }
TypeReaders​
Represents all Revolt.Commands.Readers.TypeReader loaded within Revolt.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​
Task<Revolt.Commands.Info.ModuleInfo>
Parameters​
| Type | Name |
|---|---|
System.String | primaryAlias |
Action<Revolt.Commands.Builders.ModuleBuilder> | buildFunc |
AddModuleAsync<T>(IServiceProvider)​
Add a command module from a <see cref="!:Type"></see>.
View Source​
public Task<ModuleInfo> AddModuleAsync<T>(IServiceProvider services)
Returns​
Task<Revolt.Commands.Info.ModuleInfo>:
A task that represents the asynchronous operation for adding the module. The task result contains the
built module.
Parameters​
| Type | Name | Description |
|---|---|---|
IServiceProvider | services | The <see cref="!:IServiceProvider"></see> 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 <see cref="!:Type"></see>.
View Source​
public async Task<ModuleInfo> AddModuleAsync(Type type, IServiceProvider services)
Returns​
Task<Revolt.Commands.Info.ModuleInfo>:
A task that represents the asynchronous operation for adding the module. The task result contains the
built module.
Parameters​
| Type | Name | Description |
|---|---|---|
Type | type | The type of module. |
IServiceProvider | services | The <see cref="!:IServiceProvider"></see> for your dependency injection solution if using one; otherwise, pass null . |
AddModulesAsync(Assembly, IServiceProvider)​
Add command modules from an <see cref="!:Assembly"></see>.
View Source​
public async Task<IEnumerable<ModuleInfo>> AddModulesAsync(Assembly assembly, IServiceProvider services)
Returns​
Task<IEnumerable<Revolt.Commands.Info.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 |
|---|---|---|
Assembly | assembly | The <see cref="!:Assembly"></see> containing command modules. |
IServiceProvider | services | The <see cref="!:IServiceProvider"></see> 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​
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 |
|---|---|---|
| Revolt.Commands.Info.ModuleInfo | module | The Revolt.Commands.Info.ModuleInfo to be removed from the service. |
RemoveModuleAsync<T>()​
Removes the command module.
View Source​
public Task<bool> RemoveModuleAsync<T>()
Returns​
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​
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 |
|---|---|---|
Type | type | The <see cref="!:Type"></see> of the module. |
AddTypeReader<T>(TypeReader)​
Adds a custom Revolt.Commands.Readers.TypeReader to this Revolt.Commands.CommandService for the supplied object type. If <code data-dev-comment-type="typeparamref" class="typeparamref">T</code> is a <see cref="!:ValueType"></see>, a nullable Revolt.Commands.Readers.TypeReader will also be added. If a default Revolt.Commands.Readers.TypeReader exists for <code data-dev-comment-type="typeparamref" class="typeparamref">T</code>, a warning will be logged and the default Revolt.Commands.Readers.TypeReader will be replaced.
View Source​
public void AddTypeReader<T>(TypeReader reader)
Parameters​
| Type | Name | Description |
|---|---|---|
| Revolt.Commands.Readers.TypeReader | reader | An instance of the Revolt.Commands.Readers.TypeReader to be added. |
Type Parameters​
| Name | Description |
|---|---|
T | The object type to be read by the |
AddTypeReader(Type, TypeReader)​
Adds a custom Revolt.Commands.Readers.TypeReader to this Revolt.Commands.CommandService for the supplied object type. If <code data-dev-comment-type="paramref" class="paramref">type</code> is a <see cref="!:ValueType"></see>, a nullable Revolt.Commands.Readers.TypeReader for the value type will also be added. If a default Revolt.Commands.Readers.TypeReader exists for <code data-dev-comment-type="paramref" class="paramref">type</code>, a warning will be logged and the default Revolt.Commands.Readers.TypeReader will be replaced.
View Source​
public void AddTypeReader(Type type, TypeReader reader)
Parameters​
| Type | Name | Description |
|---|---|---|
Type | type | A <see cref="!:Type"></see> instance for the type to be read. |
| Revolt.Commands.Readers.TypeReader | reader | An instance of the Revolt.Commands.Readers.TypeReader to be added. |
AddTypeReader<T>(TypeReader, Boolean)​
Adds a custom Revolt.Commands.Readers.TypeReader to this Revolt.Commands.CommandService for the supplied object type. If <code data-dev-comment-type="typeparamref" class="typeparamref">T</code> is a <see cref="!:ValueType"></see>, a nullable Revolt.Commands.Readers.TypeReader will also be added.
View Source​
public void AddTypeReader<T>(TypeReader reader, bool replaceDefault)
Parameters​
| Type | Name | Description |
|---|---|---|
| Revolt.Commands.Readers.TypeReader | reader | An instance of the Revolt.Commands.Readers.TypeReader to be added. |
System.Boolean | replaceDefault |
Defines whether the Revolt.Commands.Readers.TypeReader should replace the default one for <see cref="!:Type"></see> if it exists. |
Type Parameters​
| Name | Description |
|---|---|
T | The object type to be read by the |
AddTypeReader(Type, TypeReader, Boolean)​
Adds a custom Revolt.Commands.Readers.TypeReader to this Revolt.Commands.CommandService for the supplied object type. If <code data-dev-comment-type="paramref" class="paramref">type</code> is a <see cref="!:ValueType"></see>, a nullable Revolt.Commands.Readers.TypeReader for the value type will also be added.
View Source​
public void AddTypeReader(Type type, TypeReader reader, bool replaceDefault)
Parameters​
| Type | Name | Description |
|---|---|---|
Type | type | A <see cref="!:Type"></see> instance for the type to be read. |
| Revolt.Commands.Readers.TypeReader | reader | An instance of the Revolt.Commands.Readers.TypeReader to be added. |
System.Boolean | replaceDefault |
Defines whether the Revolt.Commands.Readers.TypeReader should replace the default one for <see cref="!:Type"></see> if it exists. |
Search(ICommandContext, Int32)​
Searches for the command.
View Source​
public SearchResult Search(ICommandContext context, int argPos)
Returns​
Revolt.Commands.Results.SearchResult: The result containing the matching commands.
Parameters​
| Type | Name | Description |
|---|---|---|
| Revolt.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​
Revolt.Commands.Results.SearchResult: The result containing the matching commands.
Parameters​
| Type | Name | Description |
|---|---|---|
| Revolt.Commands.ICommandContext | context | The context of the command. |
System.String | input | The command string. |
Search(String)​
View Source​
public SearchResult Search(string input)
Returns​
Revolt.Commands.Results.SearchResult
Parameters​
| Type | Name |
|---|---|
System.String | input |
ExecuteAsync(ICommandContext, Int32, IServiceProvider, MultiMatchHandling)​
View Source​
public Task<IResult> ExecuteAsync(ICommandContext context, int argPos, IServiceProvider services, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception)
Returns​
Task<Revolt.Commands.Results.IResult>
Parameters​
| Type | Name |
|---|---|
| Revolt.Commands.ICommandContext | context |
System.Int32 | argPos |
IServiceProvider | services |
| Revolt.Commands.MultiMatchHandling | multiMatchHandling |
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​
Task<Revolt.Commands.Results.IResult>:
A task that represents the asynchronous execution operation. The task result contains the result of the
command execution.
Parameters​
| Type | Name | Description |
|---|---|---|
| Revolt.Commands.ICommandContext | context | The context of the command. |
System.String | input | The command string. |
IServiceProvider | services | The service to be used in the command's dependency injection. |
| Revolt.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 |
Events​
Log​
Occurs when a command-related information is received.
View Source​
public event Func<LogMessage, Task> Log
Event Type​
Func<Revolt.Commands.LogMessage,Task>
CommandExecuted​
Occurs when a command is executed.
View Source​
public event Func<Optional<CommandInfo>, ICommandContext, IResult, Task> CommandExecuted
Event Type​
Func<Revolt.Commands.Optional<Revolt.Commands.Info.CommandInfo>,Revolt.Commands.ICommandContext,Revolt.Commands.Results.IResult,Task>
Extension Methods​
- Revolt.Commands.CommandService.Revolt.Commands.Extensions.CommandServiceExtensions.GetExecutableCommandsAsync(Revolt.Commands.ICommandContext,IServiceProvider)