WaxMenu 0.0.1

dotnet add package WaxMenu --version 0.0.1                
NuGet\Install-Package WaxMenu -Version 0.0.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="WaxMenu" Version="0.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WaxMenu --version 0.0.1                
#r "nuget: WaxMenu, 0.0.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 WaxMenu as a Cake Addin
#addin nuget:?package=WaxMenu&version=0.0.1

// Install WaxMenu as a Cake Tool
#tool nuget:?package=WaxMenu&version=0.0.1                

Introduction

WaxMenu is a library to create interactive menus and component tasks with DSharpPlus

How to use

Setup

// With DiscordClientBuilder
builder.UseWaxMenu(extension =>
    {
        // Add a menu to be used
        extension.AddMenu<GuildCommand>();
    }, new MenuExtensionConfiguration("menu", "_"));
// With ServiceProvider
builder.Services
    // ...
    .AddMenuExtension(extension =>
    {
        // Add a menu to be used
        extension.AddMenu<GuildCommand>();
    }, new MenuExtensionConfiguration("menu", "_"));

Adding a menu

You need to add a menu attribute to the class that you want to make the menu. You can use with Command extensions too <br/>Inside the class, you can add Menu Actions. This actions are triggered in every component interaction where match the requisites (See ID Pattern)

// Example
[Command("guild"), Menu("guild")]
public class GuildCommand(CiaraContext database)
{
    [Command("menu"), RequireGuild]
    public async ValueTask Menu(CommandContext context)
    {
        var idHash = Hash.HashId(context.Guild!.Id);
        var dbGuild = await database.Guilds.FindOrCreateAsync(idHash, () => new BotGuild { IdHash = idHash }, database);
        
        await context.RespondAsync(GuildMenuBuilder.MainMenu(context.Guild.Name, dbGuild));
    }

    [MenuAction("home")]
    public async ValueTask Menu(MenuContext context)
    {
        var idHash = Hash.HashId(context.Guild.Id);
        var dbGuild = await database.Guilds.FindOrCreateAsync(idHash, () => new BotGuild { IdHash = idHash }, database);
        
        await context.EditResponse(GuildMenuBuilder.MainMenu(context.Guild.Name, dbGuild));
    }

    [MenuAction("newmember")]
    public async ValueTask NewMember(MenuContext context)
    {
        var idHash = Hash.HashId(context.Guild.Id);
        var dbGuild = await database.Guilds.FindOrCreateAsync(idHash, () => new BotGuild { IdHash = idHash }, database);

        await context.EditResponse(GuildMenuBuilder.NewMemberMenu(context.Guild.Channels.Values,
            context.Guild.Name, context.Channel.Id, dbGuild));
    }

    [MenuAction("newmemberselect")]
    public async ValueTask NewMemberSelect(MenuContext context)
    {
        var idHash = Hash.HashId(context.Guild.Id);
        var dbGuild = await database.Guilds.FindOrCreateAsync(idHash, () => new BotGuild { IdHash = idHash }, database);

        dbGuild.MemberJoinViewChannelId = ulong.Parse(context.SelectValues[0]);
        database.Guilds.Update(dbGuild);
        await database.SaveChangesAsync();

        await context.EditResponse(GuildMenuBuilder.NewMemberMenu(context.Guild.Channels.Values,
            context.Guild.Name, context.Channel.Id, dbGuild));
    }
}

ID Pattern

The component CustomId should match this pattern prefix_command_subcommand_param1_param2

  • prefix* The prefix that you added on configuration
  • _* The separator that you added on configuration
  • command* Is the name of the menu ([Menu("guild")])
  • subcommand* Is the name of the action ([MenuAction("home")])
  • params(optional) Are parameters that is passed through the method (See Action Parameters)
// Example
messageBuilder.AddComponents(new DiscordButtonComponent(DiscordButtonStyle.Secondary, "menu_guild_home", "Home"));

Action Parameters

Type Format Note
bool true/false
byte 0 - 255
sbyte -128 - 127
char 'c'
decimal 547589.43642
double 325436.4535
float 3524.56
int -352456
uint 246356
long -32534456254
ulong 352434436346
short -2356
ushort 4367
string "text"
DiscordChannel 3253423463456 ID
DiscordUser 4364536534623 ID
DiscordGuild 5473536453632 ID
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.1 90 8/18/2024