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

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