Skip to main content

Class CommandService

Provides a framework for building Discord commands.

Assembly: Revolt.Net.Commands.dll​
View Source​
Declaration
public class CommandService : IDisposable

Properties​

Modules​

Represents all modules loaded within Revolt.Commands.CommandService.

View Source​
Declaration
public IEnumerable<ModuleInfo> Modules { get; }

Commands​

Represents all commands loaded within Revolt.Commands.CommandService.

View Source​
Declaration
public IEnumerable<CommandInfo> Commands { get; }

TypeReaders​

Represents all Revolt.Commands.Readers.TypeReader loaded within Revolt.Commands.CommandService.

View Source​
Declaration
public ILookup<Type, TypeReader> TypeReaders { get; }

Methods​

CreateModuleAsync(String, Action<ModuleBuilder>)​

View Source​
Declaration
public async Task<ModuleInfo> CreateModuleAsync(string primaryAlias, Action<ModuleBuilder> buildFunc)
Returns​

Task<Revolt.Commands.Info.ModuleInfo>

Parameters​
TypeName
System.StringprimaryAlias
Action<Revolt.Commands.Builders.ModuleBuilder>buildFunc

AddModuleAsync<T>(IServiceProvider)​

Add a command module from a <see cref="!:Type"></see>.

View Source​
Declaration
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​
TypeNameDescription
IServiceProviderservicesThe <see cref="!:IServiceProvider"></see> for your dependency injection solution if using one; otherwise, pass null.
Type Parameters​
NameDescription
TThe type of module.

AddModuleAsync(Type, IServiceProvider)​

Adds a command module from a <see cref="!:Type"></see>.

View Source​
Declaration
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​
TypeNameDescription
TypetypeThe type of module.
IServiceProviderservicesThe <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​
Declaration
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​
TypeNameDescription
AssemblyassemblyThe <see cref="!:Assembly"></see> containing command modules.
IServiceProviderservicesThe <see cref="!:IServiceProvider"></see> for your dependency injection solution if using one; otherwise, pass null.

RemoveModuleAsync(ModuleInfo)​

Removes the command module.

View Source​
Declaration
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​
TypeNameDescription
Revolt.Commands.Info.ModuleInfomoduleThe Revolt.Commands.Info.ModuleInfo to be removed from the service.

RemoveModuleAsync<T>()​

Removes the command module.

View Source​
Declaration
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​
NameDescription
TThe of the module.

RemoveModuleAsync(Type)​

Removes the command module.

View Source​
Declaration
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​
TypeNameDescription
TypetypeThe <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​
Declaration
public void AddTypeReader<T>(TypeReader reader)
Parameters​
TypeNameDescription
Revolt.Commands.Readers.TypeReaderreaderAn instance of the Revolt.Commands.Readers.TypeReader to be added.
Type Parameters​
NameDescription
TThe 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​
Declaration
public void AddTypeReader(Type type, TypeReader reader)
Parameters​
TypeNameDescription
TypetypeA <see cref="!:Type"></see> instance for the type to be read.
Revolt.Commands.Readers.TypeReaderreaderAn 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​
Declaration
public void AddTypeReader<T>(TypeReader reader, bool replaceDefault)
Parameters​
TypeNameDescription
Revolt.Commands.Readers.TypeReaderreaderAn instance of the Revolt.Commands.Readers.TypeReader to be added.
System.BooleanreplaceDefault

Defines whether the Revolt.Commands.Readers.TypeReader should replace the default one for <see cref="!:Type"></see> if it exists. |

Type Parameters​
NameDescription
TThe 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​
Declaration
public void AddTypeReader(Type type, TypeReader reader, bool replaceDefault)
Parameters​
TypeNameDescription
TypetypeA <see cref="!:Type"></see> instance for the type to be read.
Revolt.Commands.Readers.TypeReaderreaderAn instance of the Revolt.Commands.Readers.TypeReader to be added.
System.BooleanreplaceDefault

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​
Declaration
public SearchResult Search(ICommandContext context, int argPos)
Returns​

Revolt.Commands.Results.SearchResult: The result containing the matching commands.

Parameters​
TypeNameDescription
Revolt.Commands.ICommandContextcontextThe context of the command.
System.Int32argPosThe position of which the command starts at.

Search(ICommandContext, String)​

Searches for the command.

View Source​
Declaration
public SearchResult Search(ICommandContext context, string input)
Returns​

Revolt.Commands.Results.SearchResult: The result containing the matching commands.

Parameters​
TypeNameDescription
Revolt.Commands.ICommandContextcontextThe context of the command.
System.StringinputThe command string.

Search(String)​

View Source​
Declaration
public SearchResult Search(string input)
Returns​

Revolt.Commands.Results.SearchResult

Parameters​
TypeName
System.Stringinput

ExecuteAsync(ICommandContext, Int32, IServiceProvider, MultiMatchHandling)​

View Source​
Declaration
public Task<IResult> ExecuteAsync(ICommandContext context, int argPos, IServiceProvider services, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception)
Returns​

Task<Revolt.Commands.Results.IResult>

Parameters​
TypeName
Revolt.Commands.ICommandContextcontext
System.Int32argPos
IServiceProviderservices
Revolt.Commands.MultiMatchHandlingmultiMatchHandling

ExecuteAsync(ICommandContext, String, IServiceProvider, MultiMatchHandling)​

Executes the command.

View Source​
Declaration
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​
TypeNameDescription
Revolt.Commands.ICommandContextcontextThe context of the command.
System.StringinputThe command string.
IServiceProviderservicesThe service to be used in the command's dependency injection.
Revolt.Commands.MultiMatchHandlingmultiMatchHandlingThe handling mode when multiple command matches are found.

Dispose(Boolean)​

View Source​
Declaration
protected virtual void Dispose(bool disposing)
Parameters​
TypeName
System.Booleandisposing

Events​

Log​

Occurs when a command-related information is received.

View Source​
Declaration
public event Func<LogMessage, Task> Log
Event Type​

Func<Revolt.Commands.LogMessage,Task>

CommandExecuted​

Occurs when a command is executed.

View Source​
Declaration
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)