You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

08-bulk-overwrite-of-global-slash-commands.md 1.6 KiB

12345678910111213141516171819202122232425262728293031323334353637
  1. ---
  2. uid: Guides.SlashCommands.BulkOverwrite
  3. title: Slash Command Bulk Overwrites
  4. ---
  5. If you have too many global commands then you might want to consider using the bulk overwrite function.
  6. ```cs
  7. public async Task Client_Ready() {
  8. List<ApplicationCommandProperties> applicationCommandProperties = new();
  9. try {
  10. // Simple help slash command.
  11. SlashCommandBuilder globalCommandHelp = new SlashCommandBuilder();
  12. globalCommandHelp.WithName("help");
  13. globalCommandHelp.WithDescription("Shows information about the bot.");
  14. applicationCommandProperties.Add(globalCommandHelp.Build());
  15. // Slash command with name as its parameter.
  16. SlashCommandOptionBuilder slashCommandOptionBuilder = new();
  17. slashCommandOptionBuilder.WithName("name");
  18. slashCommandOptionBuilder.WithType(ApplicationCommandOptionType.String);
  19. slashCommandOptionBuilder.WithDescription("Add a family");
  20. slashCommandOptionBuilder.WithRequired(true); // Only add this if you want it to be required
  21. SlashCommandBuilder globalCommandAddFamily = new SlashCommandBuilder();
  22. globalCommandAddFamily.WithName("add-family");
  23. globalCommandAddFamily.WithDescription("Add a family");
  24. applicationCommandProperties.Add(globalCommandAddFamily.Build());
  25. await _client.BulkOverwriteGlobalApplicationCommandsAsync(applicationCommandProperties.ToArray());
  26. } catch (ApplicationCommandException exception) {
  27. var json = JsonConvert.SerializeObject(exception.Error, Formatting.Indented);
  28. Console.WriteLine(json);
  29. }
  30. Console.WriteLine("Client Ready: Finished");
  31. }
  32. ```