Table of Contents

Class RequireNsfwAttribute

Namespace
Discord.Commands
Assembly
Discord.Net.Commands.dll

Requires the command to be invoked in a channel marked NSFW.

[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public class RequireNsfwAttribute : PreconditionAttribute
Inheritance
RequireNsfwAttribute
Inherited Members

Examples

The following example restricts the command too-cool to an NSFW-enabled channel only.

public class DankModule : ModuleBase
{
    [Command("cool")]
    public Task CoolAsync()
        => ReplyAsync("I'm cool for everyone.");

    [RequireNsfw]
    [Command("too-cool")]
    public Task TooCoolAsync()
        => ReplyAsync("You can only see this if you're cool enough.");
}

Remarks

The precondition will restrict the access of the command or module to be accessed within a guild channel that has been marked as mature or NSFW. If the channel is not of type ITextChannel or the channel is not marked as NSFW, the precondition will fail with an erroneous PreconditionResult.

Properties

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

string

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 ICommandContext

The context of the command.

command CommandInfo

The command being executed.

services IServiceProvider

The service collection used for dependency injection.

Returns

Task<PreconditionResult>