Table of Contents

Class RequireRoleAttribute

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

Requires the user invoking the command to have a specified role.

[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public class RequireRoleAttribute : PreconditionAttribute
Inheritance
RequireRoleAttribute
Inherited Members

Constructors

RequireRoleAttribute(string)

Requires that the user invoking the command to have a specific Role.

public RequireRoleAttribute(string roleName)

Parameters

roleName string

Name of the role that the user must have.

RequireRoleAttribute(ulong)

Requires that the user invoking the command to have a specific Role.

public RequireRoleAttribute(ulong roleId)

Parameters

roleId ulong

Id of the role that the user must have.

Properties

NotAGuildErrorMessage

Gets or sets the error message if the precondition fails due to being run outside of a Guild channel.

public string NotAGuildErrorMessage { get; set; }

Property Value

string

RoleId

Gets the specified Role ID of the precondition.

public ulong? RoleId { get; }

Property Value

ulong?

RoleName

Gets the specified Role name of the precondition.

public string RoleName { get; }

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>