Discord.Net.Labs
2.4.7
See the version list below for details.
dotnet add package Discord.Net.Labs --version 2.4.7
NuGet\Install-Package Discord.Net.Labs -Version 2.4.7
<PackageReference Include="Discord.Net.Labs" Version="2.4.7" />
paket add Discord.Net.Labs --version 2.4.7
#r "nuget: Discord.Net.Labs, 2.4.7"
// Install Discord.Net.Labs as a Cake Addin #addin nuget:?package=Discord.Net.Labs&version=2.4.7 // Install Discord.Net.Labs as a Cake Tool #tool nuget:?package=Discord.Net.Labs&version=2.4.7
Discord.Net Labs
Join our Discord server for support using labs
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
Known issues
Labs will not work with normal package of Playwo's InteractivityAddon. The reason is that his package depends on the base discord.net lib. You can instead use the InteractivityAddon.Labs package which implements some of the features added in Discord.Net-Labs.
How to use
Setting up labs in your project is really simple, here's how to do it:
- Remove Discord.Net from your project
- Add Discord.Net Labs nuget to your project
- Enjoy!
Listening for interactions
// Subscribe to the InteractionCreated event
client.InteractionCreated += Client_InteractionCreated;
...
private async Task Client_InteractionCreated(SocketInteraction arg)
{
switch (arg.Type) // We want to check the type of this interaction
{
//Slash commands
case InteractionType.ApplicationCommand:
await MySlashCommandHandler(arg);
break;
//Button clicks/selection dropdowns
case InteractionType.MessageComponent:
await MyMessageComponentHandler(arg);
break;
//Unused
case InteractionType.Ping:
break;
//Unknown/Unsupported
default:
Console.WriteLine("Unsupported interaction type: " + arg.Type);
break;
}
}
Handling button clicks and selection dropdowns
private async Task MyMessageComponentHandler(SocketInteraction arg)
{
// Parse the arg
var parsedArg = (SocketMessageComponent) arg;
// Get the custom ID
var customId = parsedArg.Data.CustomId;
// Get the user
var user = (SocketGuildUser) arg.User;
// Get the guild
var guild = user.Guild;
// Respond with the update message response type. This edits the original message if you have set AlwaysAcknowledgeInteractions to false.
// You can also use "ephemeral" so that only the original user of the interaction sees the message
await parsedArg.RespondAsync($"Clicked {parsedArg.Data.CustomId}!", type: InteractionResponseType.UpdateMessage, ephemeral: true);
// You can also followup with a second message
await parsedArg.FollowupAsync($"Clicked {parsedArg.Data.CustomId}!", type: InteractionResponseType.ChannelMessageWithSource, ephemeral: true);
//If you are using selection dropdowns, you can get the selected label and values using these:
var selectedLabel = ((SelectMenu) parsedArg.Message.Components.First().Components.First()).Options.FirstOrDefault(x => x.Value == parsedArg.Data.Values.FirstOrDefault())?.Label;
var selectedValue = parsedArg.Data.Values.First();
}
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.
Sending messages with buttons
Theres a new field in all SendMessageAsync
functions that takes in a MessageComponent
, you can use it like so:
var builder = new ComponentBuilder().WithButton("Hello!", customId: "id_1", ButtonStyle.Primary, row: 0);
await Context.Channel.SendMessageAsync("Test buttons!", component: builder.Build());
Sending messages with selection dropdowns
Theres a new field in all SendMessageAsync
functions that takes in a MessageComponent
, you can use it like so:
var builder = new ComponentBuilder()
.WithSelectMenu(new SelectMenuBuilder()
.WithCustomId("id_2")
.WithLabel("Select menu!")
.WithPlaceholder("This is a placeholder")
.WithOptions(new List<SelectMenuOptionBuilder>()
{
new SelectMenuOptionBuilder()
.WithLabel("Option A")
.WithEmote(Emote.Parse("<:evanpog:810017136814194698>"))
.WithDescription("Evan pog champ")
.WithValue("value1"),
new SelectMenuOptionBuilder()
.WithLabel("Option B")
.WithDescription("Option B is poggers")
.WithValue("value2")
}));
await Context.Channel.SendMessageAsync("Test selection!", component: builder.Build());
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.
Slash commands
Slash command example how to's can be found here. If you want to read some code using slash commands, you can do that here
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.6.1
- Discord.Net.Labs.Commands (>= 2.3.5)
- Discord.Net.Labs.Core (>= 2.4.5)
- Discord.Net.Labs.Rest (>= 2.4.5)
- Discord.Net.Labs.Webhook (>= 2.3.4)
- Discord.Net.Labs.WebSocket (>= 2.4.6)
-
.NETStandard 2.0
- Discord.Net.Labs.Commands (>= 2.3.5)
- Discord.Net.Labs.Core (>= 2.4.5)
- Discord.Net.Labs.Rest (>= 2.4.5)
- Discord.Net.Labs.Webhook (>= 2.3.4)
- Discord.Net.Labs.WebSocket (>= 2.4.6)
-
.NETStandard 2.1
- Discord.Net.Labs.Commands (>= 2.3.5)
- Discord.Net.Labs.Core (>= 2.4.5)
- Discord.Net.Labs.Rest (>= 2.4.5)
- Discord.Net.Labs.Webhook (>= 2.3.4)
- Discord.Net.Labs.WebSocket (>= 2.4.6)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Discord.Net.Labs:
Package | Downloads |
---|---|
Discord.KillersLibrary.Labs
This package is an Addon for Discord.Net It provides embedding pages and multi buttons for your Discord Bot. Moreover it includes support for any command framework and slash commands. |
|
Xssp.Discord.Util
Provides various utilities to simplify the use of the Discord.NET API. |
|
DNetLabRat
Button lib for Discord.Net-Labs |
|
Discord.Killer
This package is an Addon for Discord.Net. It provides enbeding pages for your Discord Bot. Moreover it includes support for any command framework. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
3.6.1 | 23,497 | 12/24/2021 | |
3.6.0 | 561 | 12/24/2021 | |
3.5.0 | 1,480 | 12/15/2021 | |
3.4.9 | 3,188 | 12/6/2021 | |
3.4.8 | 5,193 | 12/4/2021 | |
3.4.7 | 2,807 | 11/28/2021 | |
3.4.6 | 682 | 11/27/2021 | |
3.4.5 | 536 | 11/27/2021 | |
3.4.4 | 578 | 11/27/2021 | |
3.4.3 | 574 | 11/27/2021 | |
3.4.2 | 2,342 | 11/26/2021 | |
3.4.1 | 1,854 | 11/26/2021 | |
3.4.0 | 1,921 | 11/26/2021 | |
3.3.3 | 792 | 11/23/2021 | |
3.3.2 | 1,080 | 11/21/2021 | |
3.3.1 | 1,226 | 11/21/2021 | |
3.3.0 | 1,471 | 11/19/2021 | |
3.2.0 | 1,728 | 11/9/2021 | |
3.1.7 | 3,426 | 10/20/2021 | |
3.1.6 | 1,376 | 10/15/2021 | |
3.1.5 | 677 | 10/15/2021 | |
3.1.4 | 870 | 10/13/2021 | |
3.1.3 | 1,072 | 10/12/2021 | |
3.1.2 | 677 | 10/12/2021 | |
3.1.1 | 3,223 | 9/23/2021 | |
3.1.0 | 802 | 9/21/2021 | |
3.0.4 | 1,183 | 9/15/2021 | |
3.0.3 | 3,302 | 9/13/2021 | |
3.0.2 | 3,554 | 8/25/2021 | |
3.0.2-pre | 759 | 8/8/2021 | |
3.0.1 | 579 | 8/25/2021 | |
3.0.1-pre | 401 | 8/5/2021 | |
3.0.0 | 693 | 8/24/2021 | |
3.0.0-pre | 266 | 8/5/2021 | |
2.4.9 | 1,634 | 7/17/2021 | |
2.4.8 | 681 | 7/15/2021 | |
2.4.7 | 863 | 7/11/2021 | |
2.4.6 | 756 | 7/11/2021 | |
2.4.5 | 663 | 7/7/2021 | |
2.4.4 | 678 | 7/6/2021 | |
2.4.3 | 649 | 7/5/2021 | |
2.4.2 | 661 | 7/4/2021 | |
2.4.1 | 689 | 7/3/2021 | |
2.4.0 | 673 | 7/3/2021 | |
2.3.8-dev | 363 | 7/2/2021 | |
2.3.7 | 1,202 | 5/30/2021 | |
2.3.6 | 742 | 5/30/2021 | |
2.3.5 | 708 | 5/30/2021 | |
2.3.4 | 670 | 5/29/2021 | |
2.3.3 | 647 | 5/28/2021 | |
2.3.2 | 601 | 5/28/2021 | |
2.3.1 | 675 | 5/27/2021 |