Skip to main content

Class RequireContextAttribute

Requires the command to be invoked in a specified context (e.g. in guild, DM).

Assembly: Discord.Net.Commands.dll​
View Source​
Declaration
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public class RequireContextAttribute : PreconditionAttribute, _Attribute

Properties​

Contexts​

Gets the context required to execute the command.

View Source​
Declaration
public ContextType Contexts { get; }

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.

View Source​
Declaration
public override string ErrorMessage { get; set; }

Methods​

CheckPermissionsAsync(ICommandContext, CommandInfo, IServiceProvider)​

Checks if the <code data-dev-comment-type="paramref" class="paramref">command</code> has the sufficient permission to be executed.

View Source​
Declaration
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
Returns​

System.Threading.Tasks.Task<Discord.Commands.PreconditionResult>

Parameters​
TypeNameDescription
Discord.Commands.ICommandContextcontextThe context of the command.
Discord.Commands.CommandInfocommandThe command being executed.
System.IServiceProviderservicesThe service collection used for dependency injection.

Implements​

  • System.Runtime.InteropServices._Attribute