Modal Components v2 Single-select Typeconverters, Rest, and Patches (#3209)

* implement modal v2 components to rest interaction extensions

* update rest extensions inline docs

* rename respondwithmodal to respondwithmodalasync

* add type converters for single user, role, channel, mentionable selects and file-uploads

* update rest interaction module base with new async methods

* code cleanup and bug fixes in default snowflake modal typeconverter

* add default snowflake typeconverters to interaction service

* fix nre in respondwithmodal extension method
This commit is contained in:
Cenk Ergen
2025-12-23 20:17:22 +01:00
committed by GitHub
parent ad8182fce3
commit 1e27c994f9
6 changed files with 321 additions and 53 deletions

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading.Tasks;
namespace Discord.Interactions
{
@@ -337,26 +338,6 @@ namespace Discord.Interactions
MinLength = commandOption.MinLength,
};
public static Modal ToModal(this ModalInfo modalInfo, string customId, Action<ModalBuilder> modifyModal = null)
{
var builder = new ModalBuilder(modalInfo.Title, customId);
foreach (var input in modalInfo.Components)
switch (input)
{
case TextInputComponentInfo textComponent:
builder.AddTextInput(textComponent.Label, textComponent.CustomId, textComponent.Style, textComponent.Placeholder, textComponent.IsRequired ? textComponent.MinLength : null,
textComponent.MaxLength, textComponent.IsRequired, textComponent.InitialValue);
break;
default:
throw new InvalidOperationException($"{input.GetType().FullName} isn't a valid component info class");
}
modifyModal?.Invoke(builder);
return builder.Build();
}
public static GuildPermission? SanitizeGuildPermissions(this GuildPermission permissions) =>
permissions == 0 ? null : permissions;
}