Class RequireContextAttribute
Requires the command to be invoked in a specified context (e.g. in guild, DM).
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public class RequireContextAttribute : PreconditionAttribute
- Inheritance
-
RequireContextAttribute
- Inherited Members
Constructors
RequireContextAttribute(ContextType)
Requires the command to be invoked in the specified context.
public RequireContextAttribute(ContextType contexts)
Parameters
contexts
ContextTypeThe type of context the command can be invoked in. Multiple contexts can be specified by ORing the contexts together.
Examples
[Command("secret")]
[RequireContext(ContextType.DM | ContextType.Group)]
public Task PrivateOnlyAsync()
{
return ReplyAsync("shh, this command is a secret");
}
Properties
Contexts
Gets the context required to execute the command.
public ContextType Contexts { get; }
Property Value
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.