Class RequireOwnerAttribute
Requires the command to be invoked by the owner of the bot.
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public class RequireOwnerAttribute : PreconditionAttribute
- Inheritance
-
RequireOwnerAttribute
- Inherited Members
Examples
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);
}
}
Remarks
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 PreconditionResult will be returned with the message "Command can only be run by the owner of the bot."
Properties
ErrorMessage
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.
public override string ErrorMessage { get; set; }
Property Value
Methods
CheckPermissionsAsync(ICommandContext, CommandInfo, IServiceProvider)
Checks if the command
has the sufficient permission to be executed.
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
Parameters
context
ICommandContextThe context of the command.
command
CommandInfoThe command being executed.
services
IServiceProviderThe service collection used for dependency injection.