Class RequireContextAttribute
- Namespace
- Discord.Interactions
- Assembly
- Discord.Net.Interactions.dll
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
contextsContextTypeThe 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
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 command, IServiceProvider services)
Parameters
contextIInteractionContextThe context of the command.
commandICommandInfoservicesIServiceProviderThe service collection used for dependency injection.