Table of Contents

Class RequireOwnerAttribute

Namespace
Discord.Commands
Assembly
Discord.Net.Commands.dll

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."

note

This precondition will only work if the account has a TokenType of Bot ;otherwise, this precondition will always fail.

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

string

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 ICommandContext

The context of the command.

command CommandInfo

The command being executed.

services IServiceProvider

The service collection used for dependency injection.

Returns

Task<PreconditionResult>