Class SlashCommandAttribute
Makes a method available as a global slash command.
Inherited Members
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 SourceSlashCommandAttribute(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 |
---|---|---|
String | name | The name of the command. |
String | description | The description of what the command does. |
Boolean | defaultPermission | Whether the command is enabled by default when the app is added to a guild. Default: true. |
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 |
ArgumentNullException | Thrown when |
Properties
| Improve this Doc View SourceAcknowledge
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 |
---|---|
Boolean |
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 |
---|---|
Boolean |
Description
The description of what the command does.
Declaration
public string Description { get; }
Property Value
Type | Description |
---|---|
String |
Name
The name of the command.
Declaration
public string Name { get; }
Property Value
Type | Description |
---|---|
String |