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

3 years ago
3 years ago
3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940
  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. {
  9. List<ApplicationCommandProperties> applicationCommandProperties = new();
  10. try
  11. {
  12. // Simple help slash command.
  13. SlashCommandBuilder globalCommandHelp = new SlashCommandBuilder();
  14. globalCommandHelp.WithName("help");
  15. globalCommandHelp.WithDescription("Shows information about the bot.");
  16. applicationCommandProperties.Add(globalCommandHelp.Build());
  17. // Slash command with name as its parameter.
  18. SlashCommandOptionBuilder slashCommandOptionBuilder = new();
  19. slashCommandOptionBuilder.WithName("name");
  20. slashCommandOptionBuilder.WithType(ApplicationCommandOptionType.String);
  21. slashCommandOptionBuilder.WithDescription("Add a family");
  22. slashCommandOptionBuilder.WithRequired(true); // Only add this if you want it to be required
  23. SlashCommandBuilder globalCommandAddFamily = new SlashCommandBuilder();
  24. globalCommandAddFamily.WithName("add-family");
  25. globalCommandAddFamily.WithDescription("Add a family");
  26. applicationCommandProperties.Add(globalCommandAddFamily.Build());
  27. await _client.BulkOverwriteGlobalApplicationCommandsAsync(applicationCommandProperties.ToArray());
  28. }
  29. catch (ApplicationCommandException exception)
  30. {
  31. var json = JsonConvert.SerializeObject(exception.Error, Formatting.Indented);
  32. Console.WriteLine(json);
  33. }
  34. }
  35. ```