2
0
mirror of synced 2025-02-23 21:48:09 +00:00

working example of slash commands with arguments

This commit is contained in:
benbierens 2023-10-18 13:55:56 +02:00
parent f33866efc1
commit 888b19d8e5
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA

View File

@ -14,6 +14,14 @@ namespace BiblioTech
this.client = client;
client.Ready += Client_Ready;
client.SlashCommandExecuted += SlashCommandHandler;
}
private async Task SlashCommandHandler(SocketSlashCommand command)
{
var cheeseOption = command.Data.Options.SingleOrDefault(o => o.Name == "cheese");
var numberOption = command.Data.Options.SingleOrDefault(o => o.Name == "numberofthings");
await command.RespondAsync($"Dear {command.User.Username}, You executed {command.Data.Name} with cheese: {cheeseOption.Value} and number: {numberOption.Value}");
}
private async Task Client_Ready()
@ -22,13 +30,12 @@ namespace BiblioTech
var guild = client.Guilds.Single(g => g.Name == "ThatBen's server");
// Next, lets create our slash command builder. This is like the embed builder but for slash commands.
var guildCommand = new SlashCommandBuilder();
// Note: Names have to be all lowercase and match the regular expression ^[\w-]{3,32}$
guildCommand.WithName("do-thing");
// Descriptions can have a max length of 100.
guildCommand.WithDescription("This command does the thing!");
var guildCommand = new SlashCommandBuilder()
.WithName("do-thing")
.WithDescription("This command does the thing!")
.AddOption("cheese", ApplicationCommandOptionType.Boolean, "whether you like cheese", isRequired: true)
.AddOption("numberofthings", ApplicationCommandOptionType.Number, "count them please", isRequired: true)
;
//// Let's do our global command
//var globalCommand = new SlashCommandBuilder();