#Getting exception from RespondWithModalAsync()

1 messages · Page 1 of 1 (latest)

weary prism
#

This issue is super weird cause I have used modals in this way successfully before so I am not sure what could be wrong.

public async Task CustomDelete(IMessage msg)
    {
        try
        {
            _msg = msg;
            await RespondWithModalAsync<CustomModel>("Custom");
        }
        catch (Exception e)
        {
            ErrorHelper.LogError(e);
        }
    }

public class CustomModel : IModal
    {
        public string Title => "Custom Delete";

        [InputLabel("Reason")]
        [ModalTextInput("reason", TextInputStyle.Paragraph,
            "Descriptive reason for message deletion.", maxLength: 300)]
        public string Reason { get; }
    }

public async Task CustomModelTask(CustomModel modal)
    {
        try
        {
            await Moderation.Delete((SocketGuildUser)_msg.Author, modal.Reason, _msg, Context.User);
            await RespondAsync($"Deleted message from <@{_msg.Author.Id}>  |  {_msg.Author.Username}#{_msg.Author.Discriminator}", null, false, true);
        }
        catch (Exception e)
        {
            ErrorHelper.LogError(e);
        }
    }
pastel apex
weary prism
pastel apex
#

Wot

weary prism
#

And I just tried it with all lowcase and it didnt work

pastel apex
#

Uhh

#

Do you use the Interaction Framework ?

weary prism
#

Pretty sure

pastel apex
#

I don't see a ModalInteraction attribute on your CustomModelTask

weary prism
#

I use the interactionservice to register my commands if thats what you mean

weary prism
# pastel apex I don't see a ModalInteraction attribute on your `CustomModelTask`

sry cut it off

[ModalInteraction("Custom")]
[DefaultMemberPermissions(GuildPermission.Administrator)]
public async Task CustomModelTask(CustomModel modal)
{
    try
    {
        await Moderation.Delete((SocketGuildUser)_msg.Author, modal.Reason, _msg, Context.User);
        await RespondAsync($"Deleted message from <@{_msg.Author.Id}>  |  {_msg.Author.Username}#{_msg.Author.Discriminator}", null, false, true);
    }
    catch (Exception e)
    {
        ErrorHelper.LogError(e);
    }
}
tall plaza
#

commad/parameter names must be lowercase

#

custom ids can be whatever

pastel apex
#

Okay

tall plaza
#

_msg = msg;

#

@weary prism is that a static property?

weary prism
#

nope just a private IMessage? _msg;

tall plaza
#

ah.

#

interaction modules are scoped

#

=> a new one created for each interaction

pastel apex
#

Is modal Interaction in a class marked with GroupAttribute ?

tall plaza
#

than the module instance gets disposed

weary prism
#

ohhh, so it should be static?

tall plaza
#

no

#

well

#

that would partially solve the issue

#

but it would break on scale

pastel apex
#

An interaction module service could be better, no ?

tall plaza
#

so either fetch the message again by id

#

or
well

#

cache

#
private static ConcurrentDictionary<ulong, IMessage> _cache = new();
weary prism
#

oki

#

ill try those

weary prism
# tall plaza or well

small issue, ive commented out everything todo with the message and it still has the same error

tall plaza
#

huh

weary prism
#

yah

tall plaza
#

well

#

could you show the code

#

in its current state

weary prism
#
public class Delete : InteractionModuleBase
{
    //private static IMessage? _msg;

    [MessageCommand("Custom Delete")]
    [DefaultMemberPermissions(GuildPermission.Administrator)]
    public async Task CustomDelete(IMessage msg)
    {
        try
        {
            //_msg = msg;
            await RespondWithModalAsync<CustomModel>("Custom");
        }
        catch (Exception e)
        {
            ErrorHelper.LogError(e);
        }
    }
    
    public class CustomModel : IModal
    {
        public string Title => "Custom Delete";

        [InputLabel("Reason")]
        [ModalTextInput("reason", TextInputStyle.Paragraph,
            "Descriptive reason for message deletion.", maxLength: 300)]
        public string Reason { get; }
    }
    
    [ModalInteraction("Custom")]
    [DefaultMemberPermissions(GuildPermission.Administrator)]
    public async Task CustomModelTask(CustomModel modal)
    {
        try
        {
            //await Moderation.Delete((SocketGuildUser)_msg.Author, modal.Reason, _msg, Context.User);
            //await RespondAsync($"Deleted message from <@{_msg.Author.Id}>  |  {_msg.Author.Username}#{_msg.Author.Discriminator}", null, false, true);
        }
        catch (Exception e)
        {
            ErrorHelper.LogError(e);
        }
    }
}
tall plaza
#

hmm

#

and what line exactly does throw

weary prism
#

await RespondWithModalAsync<CustomModel>("Custom");

tall plaza
#

ah and also

public string Reason { get; }

should be { get; set; }

#

hmm
everything else looks alright

tall plaza
#

also

[DefaultMemberPermissions(GuildPermission.Administrator)]

on the modal interaction is redundant
it only works on slash/context menu commands

weary prism
#

the model popped up, still errored when trying to submit

#

but its progress

tall plaza
#

yeah

weary prism
#

lol

tall plaza
#

you don't respond rn

#

that's why

weary prism
#

oh

#

lol

#

im dumb

#

thx for the help

tall plaza
weary prism
tall plaza
#

ah also

#

you could just pass the message id throw modal's custom id

#

as it also supports wildcards

weary prism
#

oh

#

ill just do that then

tall plaza
#
 await RespondWithModalAsync<CustomModel>($"Custom_{msg.Id}");
weary prism
tall plaza
#
[ModalInteraction("Custom_*")]
public async Task CustomModelTask(ulong id, CustomModel modal)
{
  var msg = await Context.Channel.GetMessageAsync(id);
...
}
#

something like that