diff --git a/src/Discord.Net.Interactions/Extensions/IDiscordInteractionExtensions.cs b/src/Discord.Net.Interactions/Extensions/IDiscordInteractionExtensions.cs index 8f0987661..d970b9930 100644 --- a/src/Discord.Net.Interactions/Extensions/IDiscordInteractionExtensions.cs +++ b/src/Discord.Net.Interactions/Extensions/IDiscordInteractionExtensions.cs @@ -19,9 +19,36 @@ namespace Discord.Interactions if (!ModalUtils.TryGet(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); + } + + /// + /// Respond to an interaction with a . + /// + /// + /// This method overload uses the parameter to create a new + /// if there isn't a built one already in cache. + /// + /// Type of the implementation. + /// The interaction to respond to. + /// Interaction service instance that should be used to build s. + /// The request options for this request. + /// Delegate that can be used to modify the modal. + /// + public static async Task RespondWithModalAsync(this IDiscordInteraction interaction, string customId, InteractionService interactionService, + RequestOptions options = null, Action modifyModal = null) + where T : class, IModal + { + var modalInfo = ModalUtils.GetOrAdd(interactionService); + + await SendModalResponseAsync(interaction, customId, modalInfo, options, modifyModal); + } + + private static async Task SendModalResponseAsync(IDiscordInteraction interaction, string customId, ModalInfo modalInfo, RequestOptions options = null, Action 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: