Search Results for

    Show / Hide Table of Contents

    Class RequireNsfwAttribute

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

    Inheritance
    Object
    PreconditionAttribute
    RequireNsfwAttribute
    Inherited Members
    PreconditionAttribute.Group
    PreconditionAttribute.ErrorMessage
    Namespace: Discord.Interactions
    Assembly: Discord.Net.Interactions.dll
    Syntax
    public class RequireNsfwAttribute : PreconditionAttribute
    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.

    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.");
    }

    Methods

    | Improve this Doc View Source

    CheckRequirementsAsync(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>
    Overrides
    PreconditionAttribute.CheckRequirementsAsync(IInteractionContext, ICommandInfo, IServiceProvider)

    Theme

    • Improve this Doc
    • View Source
    In This Article
    Back to top Discord.Net (c) 2015-2022 3.7.2