Table of Contents

Class RequireRoleAttribute

Namespace
Discord.Interactions
Assembly
Discord.Net.Interactions.dll

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

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

CheckRequirementsAsync(IInteractionContext, ICommandInfo, IServiceProvider)

Checks if the commandInfo command to be executed meets the precondition requirements.

public override Task<PreconditionResult> CheckRequirementsAsync(IInteractionContext context, ICommandInfo commandInfo, IServiceProvider services)

Parameters

context IInteractionContext

The context of the command.

commandInfo ICommandInfo

The command being executed.

services IServiceProvider

The service collection used for dependency injection.

Returns

Task<PreconditionResult>