Class RequireContextPermissionAttribute
- Namespace
- Discord.Interactions
- Assembly
- Discord.Net.Interactions.dll
Requires the bot to have a specific permission in the context a command is invoked in.
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public class RequireContextPermissionAttribute : PreconditionAttribute
- Inheritance
-
RequireContextPermissionAttribute
- Inherited Members
Constructors
RequireContextPermissionAttribute(ChannelPermission)
Requires that the bot account to have a specific ChannelPermission.
public RequireContextPermissionAttribute(ChannelPermission permission)
Parameters
permission
ChannelPermissionThe ChannelPermission that the bot must have. Multiple permissions can be specified by ORing the permissions together.
RequireContextPermissionAttribute(GuildPermission)
Requires the bot account to have a specific GuildPermission.
public RequireContextPermissionAttribute(GuildPermission permission)
Parameters
permission
GuildPermissionThe GuildPermission that the bot must have. Multiple permissions can be specified by ORing the permissions together.
Remarks
This precondition will always fail if the command is being invoked in a IPrivateChannel.
Properties
ChannelPermission
Gets the specified ChannelPermission of the precondition.
public ChannelPermission? ChannelPermission { get; }
Property Value
GuildPermission
Gets the specified GuildPermission of the precondition.
public GuildPermission? GuildPermission { get; }
Property Value
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
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
context
IInteractionContextThe context of the command.
command
ICommandInfoservices
IServiceProviderThe service collection used for dependency injection.