Browse Source

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
pull/1923/head
Simon Hjorthøj GitHub 3 years ago
parent
commit
f1a7ee843e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 0 deletions
  1. +31
    -0
      docs/guides/interactions/application-commands/slash-commands/08-bulk-overwrite-of-global-slash-commands.md

+ 31
- 0
docs/guides/interactions/application-commands/slash-commands/08-bulk-overwrite-of-global-slash-commands.md View File

@@ -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> 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");
}
```

Loading…
Cancel
Save