XeroxDev.DSharpPlus.ModalCommands 2.0.0

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

// Install XeroxDev.DSharpPlus.ModalCommands as a Cake Tool
#tool nuget:?package=XeroxDev.DSharpPlus.ModalCommands&version=2.0.0                

Table of content

1. Badges

Forks Stars Watchers Contributors

Issues Issues closed

Issues-pr Issues-pr closed PRs welcome

Version Downloads

Awesome Badges

2. What is this package

This is an extension for DSharpPlus to use modals like commands from CommandsNext.

3. Example

3.1 Registration

var modalCommands = _client.UseModalCommands(new ModalCommandsConfiguration()
    Services = _sp

3.2 Creating a modal

var modal = ModalBuilder.Create("food")
    .WithTitle("Super cool modal!")
    .AddComponents(new TextInputComponent("Favorite food", "fav-food", "Pizza, Icecream, etc", max_length: 30))
    .AddComponents(new TextInputComponent("Why?", "why-fav", "Because it tastes good", required: false, style: TextInputStyle.Paragraph));

You can also create a modal in the normal way, but remember to add the Prefix set in ModalCommandsConfiguration ( Default >) with WithCustomId.

3.3 Listen for modal submit

public class FoodModal : ModalCommandModule
    public async Task GetFavFoodAsync(ModalContext ctx, string food, string reason)
        await ctx.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource,
            new DiscordInteractionResponseBuilder().WithContent($"Your favorite food is: {food}. Reason: {reason}").AsEphemeral());

4. Custom arguments converter

By default, only the following arguments are supported:

  • string
  • bool
  • int
  • uint
  • long
  • ulong
  • float
  • double
  • DiscordUser
  • DiscordMember
  • DiscordRole
  • DiscordChannel

If you want to add more arguments, you can create a new argument converter like so:

    public class IntConverter : IModalArgumentConverter<int>
        // This method will convert the string to an int.
        public Task<Optional<int>> ConvertAsync(string value, ModalContext ctx)
            return Task.FromResult(int.TryParse(value, out var res) ? Optional.FromValue(res) : Optional.FromNoValue<int>());

        // This method will convert the int to a string.
        public string ConvertToString(int value) => value.ToString();

After writing your argument converter, you can register it in your ModalCommandsExtension like so:

buttonCommands.RegisterConverter(new ShortConverter());

5. Credits

I stole nearly all of this from Kuylars DSharpPlus.ButtonCommands extension

And because of this: If something doesn't work, blame Kuylar. I'm a lazy person 😛

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
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
2.0.0 406 9/23/2023
1.3.1 418 10/28/2022
1.3.0 369 10/15/2022
1.2.1 511 6/24/2022
1.1.1 390 6/4/2022
1.1.0 423 5/8/2022
1.0.1 417 5/6/2022
1.0.0 389 5/6/2022