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.

README.md 7.0 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <p align="center">
  2. <a href="https://discord-net-labs.com/" title="Click to visit the documentation!">
  3. <img src="https://discord-net-labs.com/marketing/Logo/SVG/Combinationmark%20White%20Border.svg" alt="Logo">
  4. </a>
  5. <br />
  6. <br />
  7. <a href="https://www.nuget.org/packages/Discord.Net.Labs/">
  8. <img src="https://img.shields.io/nuget/vpre/Discord.Net.Labs.svg?maxAge=2592000?style=plastic" alt="NuGet">
  9. </a>
  10. <a href="https://www.myget.org/feed/Packages/discord-net-labs">
  11. <img src="https://img.shields.io/myget/discord-net-labs/vpre/Discord.Net.Labs.svg" alt="MyGet">
  12. </a>
  13. <a href="https://dev.azure.com/Discord-Net-Labs/Discord-Net-Labs/_build/latest?definitionId=1&amp;branchName=release%2F3.x">
  14. <img src="https://dev.azure.com/Discord-Net-Labs/Discord-Net-Labs/_apis/build/status/discord-net.Discord.Net?branchName=dev" alt="Build Status">
  15. </a>
  16. <a href="https://discord.gg/dvSfUTet3K">
  17. <img src="https://discord.com/api/guilds/848176216011046962/widget.png" alt="Discord">
  18. </a>
  19. </p>
  20. This repo is a custom fork of Discord.Net that introduces the newest features of discord for testing and experimenting. Nothing here is guaranteed to work but you are more than welcome to submit bugs in the issues tabs
  21. ### ♥ Sponsor us!
  22. - If this library benefits you consider [sponsoring](https://github.com/sponsors/quinchs) the project as it really helps out. *Only sponsor if you're financially stable!*
  23. ## Known issues
  24. Labs will not work with normal package of Playwo's [InteractivityAddon](https://www.nuget.org/packages/Discord.InteractivityAddon). The reason is that his package depends on the base discord.net lib. You can instead use the [InteractivityAddon.Labs](https://www.nuget.org/packages/Discord.InteractivityAddon.Labs) package which implements some of the features added in Discord.Net-Labs.
  25. ## How to use
  26. Setting up labs in your project is really simple, here's how to do it:
  27. 1) Remove Discord.Net from your project
  28. 2) Add Discord.Net Labs nuget to your project
  29. 3) Enjoy!
  30. ## Branches
  31. ### Dev
  32. This branch is kept up to date with dnets dev branch. we pull of it to ensure that labs will work with pre existing dnet code.
  33. ### release/3.x
  34. This branch is what will be pushed to nuget, sometimes its not up to date as we wait for other features to be finished.
  35. ### old/SlashCommandService
  36. This branch is on pause and does not work currently, There is a pull request open to implement a working version of a slash command service. It can be found [here](https://github.com/Discord-Net-Labs/Discord.Net-Labs/pull/52)
  37. ### feature/xyz
  38. These branches are features for new things, you are more than welcome to clone them and give feedback in the discord server or issues tab.
  39. ## Listening for Interactions
  40. Interaction docs can be found [here](https://github.com/Discord-Net-Labs/Discord.Net-Labs/tree/release/3.x/docs/guides/interactions). They are much more in depth than this readme.
  41. ```cs
  42. // Subscribe to the InteractionCreated event
  43. client.InteractionCreated += Client_InteractionCreated;
  44. ...
  45. private async Task Client_InteractionCreated(SocketInteraction interaction)
  46. {
  47. // Checking the type of this interaction
  48. switch (interaction)
  49. {
  50. // Slash commands
  51. case SocketSlashCommand commandInteraction:
  52. await MySlashCommandHandler(commandInteraction);
  53. break;
  54. // Button clicks/selection dropdowns
  55. case SocketMessageComponent componentInteraction:
  56. await MyMessageComponentHandler(componentInteraction);
  57. break;
  58. // Unused or Unknown/Unsupported
  59. default:
  60. break;
  61. }
  62. }
  63. ```
  64. ### Simple handling slash commands
  65. ```cs
  66. private async Task MySlashCommandHandler(SocketSlashCommand interaction)
  67. {
  68. // Checking command name
  69. if (interaction.Data.Name == "ping")
  70. {
  71. // Respond to interaction with message.
  72. // You can also use "ephemeral" so that only the original user of the interaction sees the message
  73. await interaction.RespondAsync($"Pong!", ephemeral: true);
  74. // Also you can followup with a additional messages, which also can be "ephemeral"
  75. await interaction.FollowupAsync($"PongPong!", ephemeral: true);
  76. }
  77. }
  78. ```
  79. ### Simple handling button clicks and selection dropdowns
  80. ```cs
  81. private async Task MyMessageComponentHandler(SocketMessageComponent interaction)
  82. {
  83. // Get the custom ID
  84. var customId = interaction.Data.CustomId;
  85. // Get the user
  86. var user = (SocketGuildUser) interaction.User;
  87. // Get the guild
  88. var guild = user.Guild;
  89. // Respond with the update message. This edits the message which this component resides.
  90. await interaction.UpdateAsync(msgProps => msgProps.Content = $"Clicked {interaction.Data.CustomId}!");
  91. // Also you can followup with a additional messages
  92. await interaction.FollowupAsync($"Clicked {interaction.Data.CustomId}!", ephemeral: true);
  93. // If you are using selection dropdowns, you can get the selected label and values using these
  94. var selectedLabel = ((SelectMenu) interaction.Message.Components.First().Components.First()).Options.FirstOrDefault(x => x.Value == interaction.Data.Values.FirstOrDefault())?.Label;
  95. var selectedValue = interaction.Data.Values.First();
  96. }
  97. ```
  98. > Note: The example above assumes that the selection dropdown is expecting only 1 returned value, if you configured your dropdown for multiple values, you'll need to modify the code slightly.
  99. ### Sending messages with buttons
  100. Theres a new field in all `SendMessageAsync` functions that takes in a `MessageComponent`, you can use it like so:
  101. ```cs
  102. var builder = new ComponentBuilder().WithButton("Hello!", customId: "id_1", ButtonStyle.Primary, row: 0);
  103. await Context.Channel.SendMessageAsync("Test buttons!", component: builder.Build());
  104. ```
  105. ### Sending messages with selection dropdowns
  106. Theres a new field in all `SendMessageAsync` functions that takes in a `MessageComponent`, you can use it like so:
  107. ```cs
  108. var builder = new ComponentBuilder()
  109. .WithSelectMenu(new SelectMenuBuilder()
  110. .WithCustomId("id_2")
  111. .WithPlaceholder("This is a placeholder")
  112. .AddOption(
  113. label: "Option",
  114. value: "value1",
  115. description: "Evan pog champ",
  116. emote: Emote.Parse("<:evanpog:810017136814194698>")
  117. )
  118. .AddOption("Option B", "value2", "Option B is poggers")
  119. );
  120. await Context.Channel.SendMessageAsync("Test selection!", component: builder.Build());
  121. ```
  122. > Note: You can only have 5 buttons per row and 5 rows per message. If a row contains a selection dropdown it cannot contain any buttons.
  123. ## Slash Commands & Context Menu Commands
  124. Slash command & Context command examples and how to's can be found [here](https://github.com/Discord-Net-Labs/Discord.Net-Labs/tree/release/3.x/docs/guides/interactions/application-commands).
  125. ## Message Components
  126. Message components (buttons, menus, etc) examples and how to's can be found [here](https://github.com/Discord-Net-Labs/Discord.Net-Labs/tree/release/3.x/docs/guides/interactions/message-components)