From f1a7ee843ebbef385d2800a429ccb422721b5cc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Hjorth=C3=B8j?= Date: Mon, 13 Sep 2021 09:05:30 +0200 Subject: [PATCH] Created 08-bulk-overwrite-of-global-slash-commands.md (#138) * Create Create 08-bulk-overwrite-of-global-slash-commands.md Just added what i was trying to figure out it might help others that are looking for an example. * added a little comment * Removed create from file name --- ...bulk-overwrite-of-global-slash-commands.md | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 docs/guides/interactions/application-commands/slash-commands/08-bulk-overwrite-of-global-slash-commands.md diff --git a/docs/guides/interactions/application-commands/slash-commands/08-bulk-overwrite-of-global-slash-commands.md b/docs/guides/interactions/application-commands/slash-commands/08-bulk-overwrite-of-global-slash-commands.md new file mode 100644 index 000000000..71bc29653 --- /dev/null +++ b/docs/guides/interactions/application-commands/slash-commands/08-bulk-overwrite-of-global-slash-commands.md @@ -0,0 +1,31 @@ +If you have too many global commands then you might want to consider doing a bulk overwrite. +```cs +public async Task Client_Ready() { + List applicationCommandProperties = new(); + try { + // Simple help slash command. + SlashCommandBuilder globalCommandHelp = new SlashCommandBuilder(); + globalCommandHelp.WithName("help"); + globalCommandHelp.WithDescription("Shows information about the bot."); + applicationCommandProperties.Add(globalCommandHelp.Build()); + + // Slash command with name as its parameter. + SlashCommandOptionBuilder slashCommandOptionBuilder = new(); + slashCommandOptionBuilder.WithName("name"); + slashCommandOptionBuilder.WithType(ApplicationCommandOptionType.String); + slashCommandOptionBuilder.WithDescription("Add a family"); + slashCommandOptionBuilder.WithRequired(true); // Only add this if you want it to be required + + SlashCommandBuilder globalCommandAddFamily = new SlashCommandBuilder(); + globalCommandAddFamily.WithName("add-family"); + globalCommandAddFamily.WithDescription("Add a family"); + applicationCommandProperties.Add(globalCommandAddFamily.Build()); + + await _client.BulkOverwriteGlobalApplicationCommandsAsync(applicationCommandProperties.ToArray()); + } catch (ApplicationCommandException exception) { + var json = JsonConvert.SerializeObject(exception.Error, Formatting.Indented); + Console.WriteLine(json); + } + Console.WriteLine("Client Ready: Finished"); +} +```