Browse Source

add RespondWithModalAsync method for initializing missing ModalInfos on runtime

pull/2369/head
Cenngo 3 years ago
parent
commit
0f14ef6ca1
1 changed files with 15 additions and 1 deletions
  1. +15
    -1
      src/Discord.Net.Interactions/Extensions/IDiscordInteractionExtensions.cs

+ 15
- 1
src/Discord.Net.Interactions/Extensions/IDiscordInteractionExtensions.cs View File

@@ -19,9 +19,23 @@ namespace Discord.Interactions
if (!ModalUtils.TryGet<T>(out var modalInfo))
throw new ArgumentException($"{typeof(T).FullName} isn't referenced by any registered Modal Interaction Command and doesn't have a cached {typeof(ModalInfo)}");

await SendModalResponseAsync(interaction, customId, modalInfo, options, modifyModal);
}

public static async Task RespondWithModalSafelyAsync<T>(this IDiscordInteraction interaction, string customId, InteractionService interactionService,
RequestOptions options = null, Action<ModalBuilder> modifyModal = null)
where T : class, IModal
{
var modalInfo = ModalUtils.GetOrAdd<T>(interactionService);

await SendModalResponseAsync(interaction, customId, modalInfo, options, modifyModal);
}

private static async Task SendModalResponseAsync(IDiscordInteraction interaction, string customId, ModalInfo modalInfo, RequestOptions options = null, Action<ModalBuilder> modifyModal = null)
{
var builder = new ModalBuilder(modalInfo.Title, customId);

foreach(var input in modalInfo.Components)
foreach (var input in modalInfo.Components)
switch (input)
{
case TextInputComponentInfo textComponent:


Loading…
Cancel
Save