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.

creating-context-menu-commands.md 5.3 KiB

Implemented Context Menus (#106) * Update README.md * Update README.md * Fix SocketSlashCommandDataOption to use long for Number instead of int (#89) * Application webhooks (#86) * Added webhook components for hooks having an application ID. * resolved #88 * resolved #85 * Update device for gateway * Fix MessageProperties.Embed being ignored in some methods that modifies a message (#92) * Update label/description lengths for selects (ref: https://github.com/discord/discord-api-docs/pull/3598/files) (#91) https://github.com/discord/discord-api-docs/pull/3598/files * Fix tests (#90) * Fix gateway serialization to include nulls (#96) * Add missing guild permissions (#93) * Update GuildPermissions.cs * Update GuildPermissionsTests.cs * Add banner and accent color to user and some fixes/improvements (#81) * Add banner and accent color to user and some fixes * Fix * Fix! * increase size of user banners to 256 * Some changes and mini refactor of color class * add constant maxDecimalValue to color and checks with exceptions * add `NotSupportedException` for `BannerId` and `AccentColor` in `SocketWebhookUser` * Update ComponentBuilder.cs - `MaxLabelLength` from `ComponentBuilder` moved to `ButtonBuilder` - Added `MaxLabelLength` for `SelectMenuOptionBuilder` - Changed `MaxDescriptionLength` to 100 * Interface Method Declarations for Interaction Methods (#99) * added interface method declarations * inline docs * Fix serialization error * meta: bump versions * Fix debug pragma * meta: bump version * Remove rich presence button * Assign CurrentUserId in Sharded Client (#100) * added interface method declarations * inline docs * current user id assignment in sharded client * Allow EmbedBuilder.ImageUrl to use attachment scheme syntax (#104) * Make Webhook ApplicationId nullable instead of optional + fix IDiscordInteraction DeferAsync method (#110) * Make Webhook ApplicationId nullable instead of optional * Fix IDiscordInteraction DeferAsync to account for ephemeral defer * Fix application command and thread starter messages being created as SocketSystemMessage * Added description of ApplicationCommandType Enums * Requested Fixes renamed SocketApplicationUserCommand to SocketUserCommand renamed SocketApplicationMessageCommand to SocketMessageCommand using ContextMenuCreationProperties for both User and Message commands * Added Summary to public members removed whitespace from DiscordRestApiClient.cs * Fixing guide to use switch statement * implemented TrySendApplicationCommandAsync * implemented ephemeral in SocketCommandBase Defer, and RespondAsync. assigning int 64 was error. changed to "MessageFlags.Ephemeral", built and tested to work. * removed ApplicationCommandType from SocketUser and SocketMessageCommandData Co-authored-by: Quin Lynch <49576606+quinchs@users.noreply.github.com> Co-authored-by: František Boháček <fandabohacek@gmail.com> Co-authored-by: quin lynch <lynchquin@gmail.com> Co-authored-by: d4n3436 <dan3436@hotmail.com> Co-authored-by: MrCakeSlayer <13650699+MrCakeSlayer@users.noreply.github.com> Co-authored-by: Nikon <47792796+INikonI@users.noreply.github.com> Co-authored-by: Cenk Ergen <57065323+Cenngo@users.noreply.github.com>
3 years ago
Implemented Context Menus (#106) * Update README.md * Update README.md * Fix SocketSlashCommandDataOption to use long for Number instead of int (#89) * Application webhooks (#86) * Added webhook components for hooks having an application ID. * resolved #88 * resolved #85 * Update device for gateway * Fix MessageProperties.Embed being ignored in some methods that modifies a message (#92) * Update label/description lengths for selects (ref: https://github.com/discord/discord-api-docs/pull/3598/files) (#91) https://github.com/discord/discord-api-docs/pull/3598/files * Fix tests (#90) * Fix gateway serialization to include nulls (#96) * Add missing guild permissions (#93) * Update GuildPermissions.cs * Update GuildPermissionsTests.cs * Add banner and accent color to user and some fixes/improvements (#81) * Add banner and accent color to user and some fixes * Fix * Fix! * increase size of user banners to 256 * Some changes and mini refactor of color class * add constant maxDecimalValue to color and checks with exceptions * add `NotSupportedException` for `BannerId` and `AccentColor` in `SocketWebhookUser` * Update ComponentBuilder.cs - `MaxLabelLength` from `ComponentBuilder` moved to `ButtonBuilder` - Added `MaxLabelLength` for `SelectMenuOptionBuilder` - Changed `MaxDescriptionLength` to 100 * Interface Method Declarations for Interaction Methods (#99) * added interface method declarations * inline docs * Fix serialization error * meta: bump versions * Fix debug pragma * meta: bump version * Remove rich presence button * Assign CurrentUserId in Sharded Client (#100) * added interface method declarations * inline docs * current user id assignment in sharded client * Allow EmbedBuilder.ImageUrl to use attachment scheme syntax (#104) * Make Webhook ApplicationId nullable instead of optional + fix IDiscordInteraction DeferAsync method (#110) * Make Webhook ApplicationId nullable instead of optional * Fix IDiscordInteraction DeferAsync to account for ephemeral defer * Fix application command and thread starter messages being created as SocketSystemMessage * Added description of ApplicationCommandType Enums * Requested Fixes renamed SocketApplicationUserCommand to SocketUserCommand renamed SocketApplicationMessageCommand to SocketMessageCommand using ContextMenuCreationProperties for both User and Message commands * Added Summary to public members removed whitespace from DiscordRestApiClient.cs * Fixing guide to use switch statement * implemented TrySendApplicationCommandAsync * implemented ephemeral in SocketCommandBase Defer, and RespondAsync. assigning int 64 was error. changed to "MessageFlags.Ephemeral", built and tested to work. * removed ApplicationCommandType from SocketUser and SocketMessageCommandData Co-authored-by: Quin Lynch <49576606+quinchs@users.noreply.github.com> Co-authored-by: František Boháček <fandabohacek@gmail.com> Co-authored-by: quin lynch <lynchquin@gmail.com> Co-authored-by: d4n3436 <dan3436@hotmail.com> Co-authored-by: MrCakeSlayer <13650699+MrCakeSlayer@users.noreply.github.com> Co-authored-by: Nikon <47792796+INikonI@users.noreply.github.com> Co-authored-by: Cenk Ergen <57065323+Cenngo@users.noreply.github.com>
3 years ago
Implemented Context Menus (#106) * Update README.md * Update README.md * Fix SocketSlashCommandDataOption to use long for Number instead of int (#89) * Application webhooks (#86) * Added webhook components for hooks having an application ID. * resolved #88 * resolved #85 * Update device for gateway * Fix MessageProperties.Embed being ignored in some methods that modifies a message (#92) * Update label/description lengths for selects (ref: https://github.com/discord/discord-api-docs/pull/3598/files) (#91) https://github.com/discord/discord-api-docs/pull/3598/files * Fix tests (#90) * Fix gateway serialization to include nulls (#96) * Add missing guild permissions (#93) * Update GuildPermissions.cs * Update GuildPermissionsTests.cs * Add banner and accent color to user and some fixes/improvements (#81) * Add banner and accent color to user and some fixes * Fix * Fix! * increase size of user banners to 256 * Some changes and mini refactor of color class * add constant maxDecimalValue to color and checks with exceptions * add `NotSupportedException` for `BannerId` and `AccentColor` in `SocketWebhookUser` * Update ComponentBuilder.cs - `MaxLabelLength` from `ComponentBuilder` moved to `ButtonBuilder` - Added `MaxLabelLength` for `SelectMenuOptionBuilder` - Changed `MaxDescriptionLength` to 100 * Interface Method Declarations for Interaction Methods (#99) * added interface method declarations * inline docs * Fix serialization error * meta: bump versions * Fix debug pragma * meta: bump version * Remove rich presence button * Assign CurrentUserId in Sharded Client (#100) * added interface method declarations * inline docs * current user id assignment in sharded client * Allow EmbedBuilder.ImageUrl to use attachment scheme syntax (#104) * Make Webhook ApplicationId nullable instead of optional + fix IDiscordInteraction DeferAsync method (#110) * Make Webhook ApplicationId nullable instead of optional * Fix IDiscordInteraction DeferAsync to account for ephemeral defer * Fix application command and thread starter messages being created as SocketSystemMessage * Added description of ApplicationCommandType Enums * Requested Fixes renamed SocketApplicationUserCommand to SocketUserCommand renamed SocketApplicationMessageCommand to SocketMessageCommand using ContextMenuCreationProperties for both User and Message commands * Added Summary to public members removed whitespace from DiscordRestApiClient.cs * Fixing guide to use switch statement * implemented TrySendApplicationCommandAsync * implemented ephemeral in SocketCommandBase Defer, and RespondAsync. assigning int 64 was error. changed to "MessageFlags.Ephemeral", built and tested to work. * removed ApplicationCommandType from SocketUser and SocketMessageCommandData Co-authored-by: Quin Lynch <49576606+quinchs@users.noreply.github.com> Co-authored-by: František Boháček <fandabohacek@gmail.com> Co-authored-by: quin lynch <lynchquin@gmail.com> Co-authored-by: d4n3436 <dan3436@hotmail.com> Co-authored-by: MrCakeSlayer <13650699+MrCakeSlayer@users.noreply.github.com> Co-authored-by: Nikon <47792796+INikonI@users.noreply.github.com> Co-authored-by: Cenk Ergen <57065323+Cenngo@users.noreply.github.com>
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # Creating context menu commands.
  2. There are two kinds of Context Menu Commands: User Commands and Message Commands.
  3. Each of these have a Global and Guild variant.
  4. Global menu commands are available for every guild that adds your app. An individual app's global commands are also available in DMs if that app has a bot that shares a mutual guild with the user.
  5. Guild commands are specific to the guild you specify when making them. Guild commands are not available in DMs. Command names are unique per application within each scope (global and guild). That means:
  6. - Your app cannot have two global commands with the same name
  7. - Your app cannot have two guild commands within the same name on the same guild
  8. - Your app can have a global and guild command with the same name
  9. - Multiple apps can have commands with the same names
  10. **Note**: Apps can have a maximum of 5 global context menu commands, and an additional 5 guild-specific context menu commands per guild.
  11. If you don't have the code for a bot ready yet please follow [this guide](https://docs.stillu.cc/guides/getting_started/first-bot.html).
  12. ## UserCommandBuilder
  13. The context menu user command builder will help you create user commands. The builder has these available fields and methods:
  14. | Name | Type | Description |
  15. | -------- | -------- | ------------------------------------------------------------------------------------------------ |
  16. | Name | string | The name of this context menu command. |
  17. | WithName | Function | Sets the field name. |
  18. | Build | Function | Builds the builder into the appropriate `UserCommandProperties` class used to make Menu commands |
  19. ## MessageCommandBuilder
  20. The context menu message command builder will help you create message commands. The builder has these available fields and methods:
  21. | Name | Type | Description |
  22. | -------- | -------- | --------------------------------------------------------------------------------------------------- |
  23. | Name | string | The name of this context menu command. |
  24. | WithName | Function | Sets the field name. |
  25. | Build | Function | Builds the builder into the appropriate `MessageCommandProperties` class used to make Menu commands |
  26. **Note**: Context Menu command names can be upper and lowercase, and use spaces.
  27. Let's use the user command builder to make a global and guild command.
  28. ```cs
  29. // Let's hook the ready event for creating our commands in.
  30. client.Ready += Client_Ready;
  31. ...
  32. public async Task Client_Ready()
  33. {
  34. // Let's build a guild command! We're going to need a guild so lets just put that in a variable.
  35. var guild = client.GetGuild(guildId);
  36. // Next, lets create our user and message command builder. This is like the embed builder but for context menu commands.
  37. var guildUserCommand = new UserCommandBuilder();
  38. var guildMessageCommand = new MessageCommandBuilder();
  39. // Note: Names have to be all lowercase and match the regular expression ^[\w -]{3,32}$
  40. guildUserCommand.WithName("Guild User Command");
  41. guildMessageCommand.WithName("Guild Message Command");
  42. // Descriptions are not used with User and Message commands
  43. //guildCommand.WithDescription("");
  44. // Let's do our global commands
  45. var globalUserCommand = new UserCommandBuilder();
  46. globalCommand.WithName("Global User Command");
  47. var globalMessageCommand = new MessageCommandBuilder();
  48. globalMessageCommand.WithName("Global Message Command");
  49. try
  50. {
  51. // Now that we have our builder, we can call the BulkOverwriteApplicationCommandAsync to make our context commands. Note: this will overwrite all your previous commands with this array.
  52. await guild.BulkOverwriteApplicationCommandAsync(new ApplicationCommandProperties[]
  53. {
  54. guildUserCommand.Build(),
  55. guildMessageCommand.Build()
  56. });
  57. // With global commands we dont need the guild.
  58. await client.BulkOverwriteGlobalApplicationCommandsAsync(new ApplicationCommandProperties[]
  59. {
  60. globalUserCommand.Build(),
  61. globalMessageCommand.Build()
  62. })
  63. }
  64. catch(ApplicationCommandException exception)
  65. {
  66. // If our command was invalid, we should catch an ApplicationCommandException. This exception contains the path of the error as well as the error message. You can serialize the Error field in the exception to get a visual of where your error is.
  67. var json = JsonConvert.SerializeObject(exception.Error, Formatting.Indented);
  68. // You can send this error somewhere or just print it to the console, for this example we're just going to print it.
  69. Console.WriteLine(json);
  70. }
  71. }
  72. ```
  73. **Note**: Application commands only need to be created once. They do _not_ have to be 'created' on every startup or connection. The example simple shows creating them in the ready event as it's simpler than creating normal bot commands to register application commands.