Discord.Net.Labs 3.1.1

Suggested Alternatives

Discord.Net

There is a newer version of this package available.
See the version list below for details.
dotnet add package Discord.Net.Labs --version 3.1.1                
NuGet\Install-Package Discord.Net.Labs -Version 3.1.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Discord.Net.Labs" Version="3.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Discord.Net.Labs --version 3.1.1                
#r "nuget: Discord.Net.Labs, 3.1.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Discord.Net.Labs as a Cake Addin
#addin nuget:?package=Discord.Net.Labs&version=3.1.1

// Install Discord.Net.Labs as a Cake Tool
#tool nuget:?package=Discord.Net.Labs&version=3.1.1                

Discord.Net Labs

NuGet

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:

  1. Remove Discord.Net from your project
  2. Add Discord.Net Labs nuget to your project
  3. Enjoy!

Listening for interactions

// Subscribe to the InteractionCreated event
client.InteractionCreated += Client_InteractionCreated;

...
private async Task Client_InteractionCreated(SocketInteraction interaction)
{
  // Checking the type of this interaction
  switch (interaction)
  {
    // Slash commands
    case SocketSlashCommand commandInteraction:
      await MySlashCommandHandler(commandInteraction);
      break;
      
    // Button clicks/selection dropdowns
    case SocketMessageComponent componentInteraction:
      await MyMessageComponentHandler(componentInteraction);
      break;
      
    // Unused or Unknown/Unsupported
    default:
      break;
  }
}

Simple handling slash commands

private async Task MySlashCommandHandler(SocketSlashCommand interaction)
{
    // Checking command name
    if (interaction.Data.Name == "ping")
    {
      // Respond to interaction with message.
      // You can also use "ephemeral" so that only the original user of the interaction sees the message
      await interaction.RespondAsync($"Pong!", ephemeral: true);
      
      // Also you can followup with a additional messages, which also can be "ephemeral"
      await interaction.FollowupAsync($"PongPong!", ephemeral: true);
    }
}

Simple handling button clicks and selection dropdowns

private async Task MyMessageComponentHandler(SocketMessageComponent interaction)
{
    // Get the custom ID 
    var customId = interaction.Data.CustomId;
    // Get the user
    var user = (SocketGuildUser) interaction.User;
    // Get the guild
    var guild = user.Guild;
    
    // Respond with the update message. This edits the message which this component resides.
    await interaction.UpdateAsync(msgProps => msgProps.Content = $"Clicked {interaction.Data.CustomId}!");
    
    // Also you can followup with a additional messages
    await interaction.FollowupAsync($"Clicked {interaction.Data.CustomId}!", ephemeral: true);
    
    // If you are using selection dropdowns, you can get the selected label and values using these
    var selectedLabel = ((SelectMenu) interaction.Message.Components.First().Components.First()).Options.FirstOrDefault(x => x.Value == interaction.Data.Values.FirstOrDefault())?.Label;
    var selectedValue = interaction.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")
    .WithPlaceholder("This is a placeholder")
    .AddOption(
      label: "Option",
      value: "value1",
      description: "Evan pog champ",
      emote: Emote.Parse("<:evanpog:810017136814194698>")
    )
    .AddOption("Option B", "value2", "Option B is poggers")
  );
  
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 & Context Menu Commands

Slash command & Context command examples and how to's can be found here.

Message Components

Message components (buttons, menus, etc) examples and how to's can be found here

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

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,466 12/24/2021 3.6.1 is deprecated because it is no longer maintained.
3.6.0 560 12/24/2021 3.6.0 is deprecated because it is no longer maintained.
3.5.0 1,479 12/15/2021 3.5.0 is deprecated because it is no longer maintained.
3.4.9 3,183 12/6/2021 3.4.9 is deprecated because it is no longer maintained.
3.4.8 5,192 12/4/2021 3.4.8 is deprecated because it is no longer maintained.
3.4.7 2,806 11/28/2021 3.4.7 is deprecated because it is no longer maintained.
3.4.6 681 11/27/2021 3.4.6 is deprecated because it is no longer maintained.
3.4.5 535 11/27/2021 3.4.5 is deprecated because it is no longer maintained.
3.4.4 577 11/27/2021 3.4.4 is deprecated because it is no longer maintained.
3.4.3 573 11/27/2021 3.4.3 is deprecated because it is no longer maintained.
3.4.2 2,341 11/26/2021 3.4.2 is deprecated because it is no longer maintained.
3.4.1 1,853 11/26/2021 3.4.1 is deprecated because it is no longer maintained.
3.4.0 1,920 11/26/2021 3.4.0 is deprecated because it is no longer maintained.
3.3.3 791 11/23/2021 3.3.3 is deprecated because it is no longer maintained.
3.3.2 1,079 11/21/2021 3.3.2 is deprecated because it is no longer maintained.
3.3.1 1,225 11/21/2021 3.3.1 is deprecated because it is no longer maintained.
3.3.0 1,470 11/19/2021 3.3.0 is deprecated because it is no longer maintained.
3.2.0 1,727 11/9/2021 3.2.0 is deprecated because it is no longer maintained.
3.1.7 3,423 10/20/2021 3.1.7 is deprecated because it is no longer maintained.
3.1.6 1,375 10/15/2021 3.1.6 is deprecated because it is no longer maintained.
3.1.5 676 10/15/2021 3.1.5 is deprecated because it is no longer maintained.
3.1.4 869 10/13/2021 3.1.4 is deprecated because it is no longer maintained.
3.1.3 1,071 10/12/2021 3.1.3 is deprecated because it is no longer maintained.
3.1.2 676 10/12/2021 3.1.2 is deprecated because it is no longer maintained.
3.1.1 3,222 9/23/2021 3.1.1 is deprecated because it is no longer maintained.
3.1.0 801 9/21/2021 3.1.0 is deprecated because it is no longer maintained.
3.0.4 1,182 9/15/2021 3.0.4 is deprecated because it is no longer maintained.
3.0.3 3,301 9/13/2021 3.0.3 is deprecated because it is no longer maintained.
3.0.2 3,553 8/25/2021 3.0.2 is deprecated because it is no longer maintained.
3.0.2-pre 758 8/8/2021 3.0.2-pre is deprecated because it is no longer maintained.
3.0.1 578 8/25/2021 3.0.1 is deprecated because it is no longer maintained.
3.0.1-pre 400 8/5/2021 3.0.1-pre is deprecated because it is no longer maintained.
3.0.0 692 8/24/2021 3.0.0 is deprecated because it is no longer maintained.
3.0.0-pre 263 8/5/2021 3.0.0-pre is deprecated because it is no longer maintained.
2.4.9 1,633 7/17/2021 2.4.9 is deprecated because it is no longer maintained.
2.4.8 680 7/15/2021 2.4.8 is deprecated because it is no longer maintained.
2.4.7 862 7/11/2021 2.4.7 is deprecated because it is no longer maintained.
2.4.6 755 7/11/2021 2.4.6 is deprecated because it is no longer maintained.
2.4.5 662 7/7/2021 2.4.5 is deprecated because it is no longer maintained.
2.4.4 677 7/6/2021 2.4.4 is deprecated because it is no longer maintained.
2.4.3 648 7/5/2021 2.4.3 is deprecated because it is no longer maintained.
2.4.2 660 7/4/2021 2.4.2 is deprecated because it is no longer maintained.
2.4.1 688 7/3/2021 2.4.1 is deprecated because it is no longer maintained.
2.4.0 672 7/3/2021 2.4.0 is deprecated because it is no longer maintained.
2.3.8-dev 362 7/2/2021 2.3.8-dev is deprecated because it is no longer maintained.
2.3.7 1,199 5/30/2021 2.3.7 is deprecated because it is no longer maintained.
2.3.6 741 5/30/2021 2.3.6 is deprecated because it is no longer maintained.
2.3.5 707 5/30/2021 2.3.5 is deprecated because it is no longer maintained.
2.3.4 669 5/29/2021 2.3.4 is deprecated because it is no longer maintained.
2.3.3 646 5/28/2021 2.3.3 is deprecated because it is no longer maintained.
2.3.2 598 5/28/2021 2.3.2 is deprecated because it is no longer maintained.
2.3.1 674 5/27/2021 2.3.1 is deprecated because it is no longer maintained.