|
- using System;
- using System.Threading.Tasks;
-
- namespace Discord.Commands
- {
- /// <summary>
- /// Require that the command is invoked in a channel marked NSFW
- /// </summary>
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
- public class RequireNsfwAttribute : PreconditionAttribute
- {
- public override Task<PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider services)
- {
- if (context.Channel is ITextChannel text && text.IsNsfw)
- return Task.FromResult(PreconditionResult.FromSuccess());
- else
- return Task.FromResult(PreconditionResult.FromError("This command may only be invoked in an NSFW channel."));
- }
- }
- }
|