Class RequireContextAttribute
Requires the command to be invoked in a specified context (e.g. in guild, DM).
Namespace: Discord.Interactions
Assembly: Discord.Net.Interactions.dll
Syntax
public class RequireContextAttribute : PreconditionAttribute
Constructors
| Improve this Doc View SourceRequireContextAttribute(ContextType)
Requires the command to be invoked in the specified context.
Declaration
public RequireContextAttribute(ContextType contexts)
Parameters
Type | Name | Description |
---|---|---|
ContextType | contexts | The 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
| Improve this Doc View SourceContexts
Gets the context required to execute the command.
Declaration
public ContextType Contexts { get; }
Property Value
Type | Description |
---|---|
ContextType |
Methods
| Improve this Doc View SourceCheckRequirementsAsync(IInteractionContext, ICommandInfo, IServiceProvider)
Checks if the commandInfo
command to be executed meets the precondition requirements.
Declaration
public override Task<PreconditionResult> CheckRequirementsAsync(IInteractionContext context, ICommandInfo command, IServiceProvider services)
Parameters
Type | Name | Description |
---|---|---|
IInteractionContext | context | The context of the command. |
ICommandInfo | command | |
IServiceProvider | services | The service collection used for dependency injection. |
Returns
Type | Description |
---|---|
Task<PreconditionResult> |