Search Results for

    Show / Hide Table of Contents

    Class SlashCommandAttribute

    Makes a method available as a global slash command.

    Inheritance
    System.Object
    System.Attribute
    SlashCommandAttribute
    Inherited Members
    System.Attribute.Equals(System.Object)
    System.Attribute.GetCustomAttribute(System.Reflection.Assembly, System.Type)
    System.Attribute.GetCustomAttribute(System.Reflection.Assembly, System.Type, System.Boolean)
    System.Attribute.GetCustomAttribute(System.Reflection.MemberInfo, System.Type)
    System.Attribute.GetCustomAttribute(System.Reflection.MemberInfo, System.Type, System.Boolean)
    System.Attribute.GetCustomAttribute(System.Reflection.Module, System.Type)
    System.Attribute.GetCustomAttribute(System.Reflection.Module, System.Type, System.Boolean)
    System.Attribute.GetCustomAttribute(System.Reflection.ParameterInfo, System.Type)
    System.Attribute.GetCustomAttribute(System.Reflection.ParameterInfo, System.Type, System.Boolean)
    System.Attribute.GetCustomAttributes(System.Reflection.Assembly)
    System.Attribute.GetCustomAttributes(System.Reflection.Assembly, System.Boolean)
    System.Attribute.GetCustomAttributes(System.Reflection.Assembly, System.Type)
    System.Attribute.GetCustomAttributes(System.Reflection.Assembly, System.Type, System.Boolean)
    System.Attribute.GetCustomAttributes(System.Reflection.MemberInfo)
    System.Attribute.GetCustomAttributes(System.Reflection.MemberInfo, System.Boolean)
    System.Attribute.GetCustomAttributes(System.Reflection.MemberInfo, System.Type)
    System.Attribute.GetCustomAttributes(System.Reflection.MemberInfo, System.Type, System.Boolean)
    System.Attribute.GetCustomAttributes(System.Reflection.Module)
    System.Attribute.GetCustomAttributes(System.Reflection.Module, System.Boolean)
    System.Attribute.GetCustomAttributes(System.Reflection.Module, System.Type)
    System.Attribute.GetCustomAttributes(System.Reflection.Module, System.Type, System.Boolean)
    System.Attribute.GetCustomAttributes(System.Reflection.ParameterInfo)
    System.Attribute.GetCustomAttributes(System.Reflection.ParameterInfo, System.Boolean)
    System.Attribute.GetCustomAttributes(System.Reflection.ParameterInfo, System.Type)
    System.Attribute.GetCustomAttributes(System.Reflection.ParameterInfo, System.Type, System.Boolean)
    System.Attribute.GetHashCode()
    System.Attribute.IsDefaultAttribute()
    System.Attribute.IsDefined(System.Reflection.Assembly, System.Type)
    System.Attribute.IsDefined(System.Reflection.Assembly, System.Type, System.Boolean)
    System.Attribute.IsDefined(System.Reflection.MemberInfo, System.Type)
    System.Attribute.IsDefined(System.Reflection.MemberInfo, System.Type, System.Boolean)
    System.Attribute.IsDefined(System.Reflection.Module, System.Type)
    System.Attribute.IsDefined(System.Reflection.Module, System.Type, System.Boolean)
    System.Attribute.IsDefined(System.Reflection.ParameterInfo, System.Type)
    System.Attribute.IsDefined(System.Reflection.ParameterInfo, System.Type, System.Boolean)
    System.Attribute.Match(System.Object)
    System.Attribute.TypeId
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: Color_Chan.Discord.Commands.Attributes
    Assembly: Color-Chan.Discord.Commands.dll
    Syntax
    [AttributeUsage(AttributeTargets.Method)]
    public class SlashCommandAttribute : Attribute
    Examples

    The following example will add the slash command /ping to the application.

    public class PongCommands : SlashCommandModule
    {
        [SlashCommand("ping", "Ping Pong!")]
        public Task<Result<IDiscordInteractionResponse>> PongAsync()
        {
            // Command code...
        }
    }

    The following example will add the slash command /rolename to the application. With a required string input.

    public class RoleCommands : SlashCommandModule
    {
        [SlashCommand("rolename", "A role command")]
        public Task<Result<IDiscordInteractionResponse>> RoleNameAsync
        (
            [SlashCommandOption("name", "The name of the new role.", true)]
            string roleName
        )
        {
            // Command code...
        }
    }

    The following example will add the slash command /role to the application. With a required role input. The given role will be added to the Data, Resolved, Roles list.

    public class RoleCommands : SlashCommandModule
    {
        [SlashCommand("role", "A role command")]
        public Task<Result<IDiscordInteractionResponse>> RoleAsync
        (
            [SlashCommandOption("role", "A role.", true, DiscordApplicationCommandOptionType.Role)]
            ulong roleId
        )
        {
            // Command code...
        }
    }

    Go to the samples solution folder to see more examples.

    Constructors

    | Improve this Doc View Source

    SlashCommandAttribute(String, String, Boolean, Boolean)

    Initializes a new instance of SlashCommandAttribute.

    Declaration
    public SlashCommandAttribute(string name, string description, bool defaultPermission = true, bool acknowledge = false)
    Parameters
    Type Name Description
    System.String name

    The name of the command.

    System.String description

    The description of what the command does.

    System.Boolean defaultPermission

    Whether the command is enabled by default when the app is added to a guild. Default: true.

    System.Boolean acknowledge

    Whether or not the command should be automatically acknowledge to prevent the token from turning inactive after 3 seconds.

    Exceptions
    Type Condition
    System.ArgumentException

    Thrown when name or description doesn't match the command name requirements.

    System.ArgumentNullException

    Thrown when name or description is null.

    Properties

    | Improve this Doc View Source

    Acknowledge

    Whether or not the command should be automatically acknowledge to prevent the token from turning inactive after 3 seconds.

    Declaration
    public bool Acknowledge { get; }
    Property Value
    Type Description
    System.Boolean
    | Improve this Doc View Source

    DefaultPermission

    Whether the command is enabled by default when the app is added to a guild.

    Declaration
    public bool DefaultPermission { get; }
    Property Value
    Type Description
    System.Boolean
    | Improve this Doc View Source

    Description

    The description of what the command does.

    Declaration
    public string Description { get; }
    Property Value
    Type Description
    System.String
    | Improve this Doc View Source

    Name

    The name of the command.

    Declaration
    public string Name { get; }
    Property Value
    Type Description
    System.String
    • Improve this Doc
    • View Source
    In This Article
    Back to top Generated by DocFX