#modal response is showing the same every call

1 messages · Page 1 of 1 (latest)

next meadow
#

I'm experiencing an issue with my modal where it will run again and still have the previous response from the last time. Noticed the same response duplicated over 4 different times the modal was sent

glad folioBOT
#

Hey! Once your issue is solved, press the button below to close this thread!

hollow night
#

can you show your code? I guess you are sending again the same modal everytime

#

when I say the same, I mean the same object

next meadow
# hollow night can you show your code? I guess you are sending again the same modal everytime

class Reporting(Extension):
    def __init__(self, bot: Client) -> None:
        self.bot: Client = bot
        # self.add_extension_prerun(self.pre_run)
        asyncio.create_task(self.async_init())

    async def async_init(self):
        self.guild = await get_guild(self.bot, SERVER_ID)
        self.mod_log = await get_channel(self.bot, MODLOG_ID)
        self.report_forums = {
            "main": await get_forum(self.bot, 1211838082148737094),
            "over18": await get_forum(self.bot, 1212929316703440926),
        }

    # async def pre_run(self, ctx: BaseContext):
    #    self.run_time = Timestamp.now(UTC)

    @message_context_menu(
        name="❗ Report this Message",
        scopes=[SERVER_ID],
        dm_permission=False,
        default_member_permissions=Permissions.USE_APPLICATION_COMMANDS,
    )
    async def report_menu(self, ctx: ContextMenuContext):
        message = ctx.target
        if not isinstance(message, Message):
            return

        content = message.content.strip()

        urls = []
        for i, attachment in enumerate(message.attachments, start=1):
            urls.append(f"{i}. {attachment.url}")

        member = message.author
        reporter = ctx.author

        report_modal = Modal(
            ParagraphText(
                label="Extra details",
                custom_id="report_details",
                min_length=3,
                max_length=1000,
            ),
            title="Report a message",
            custom_id="report_modal",
        )

        is_nsfw = False
        if message.channel.id in ADULT_CHANNELS:
            is_nsfw = True
        else:
            report_modal.add_components(
                ShortText(
                    label="Does this incident contain adult content?",
                    custom_id="adult_content",
                    placeholder='Enter only "Yes" or leave blank',
                    required=False,
                    max_length=3,
                )
            )

        await ctx.send_modal(report_modal)
        modal_ctx = await ctx.bot.wait_for_modal(report_modal)

        report_details = modal_ctx.responses["report_details"]

        try:
            over18_answer = modal_ctx.responses["adult_content"]
        except KeyError:
            over18_answer = "auto"

        if is_nsfw or over18_answer:
            report_forum = self.report_forums["over18"]
            post_tag = 1212934876357992458
        else:
            report_forum = self.report_forums["main"]
            post_tag = 1212532831230627911

        forum_post = await report_forum.create_post(
            name=f"{member} in #{message.channel.name}",
            content=content or "No message text (attachment only)",
            applied_tags=[post_tag],
            allowed_mentions=AllowedMentions.none(),
        )

        if urls:
            await forum_post.send("### Attachments\n" + "\n".join(urls))

        await forum_post.send(
            (
                f"### ➡️ {message.jump_url}\n"
                f"### Extra details:\n{report_details}\n"
                f"### Report made by:\n"
                f"- {reporter.mention}\n- `{reporter.id}`\n"
                f"### Reported user:\n"
                f"- {member.mention}\n- `{member.id}`\n"
                "<@&295418997871214592>"
            ),
            allowed_mentions=AllowedMentions(roles=[295418997871214592]),
        )

        await forum_post.send(member.display_avatar.url)
        await modal_ctx.send("Your report has been sent!", ephemeral=True)
hollow night
#

oof too long

next meadow
#

its like this while im still making this. not happy with everything being hardcoded and stuff

next meadow
#

bump

next meadow
#

bump

quasi copper
#

Try adding some random value to the custom id?

next meadow
quasi copper
#

My guess is that the wait_for_modal checks the custom id, and when multiple modals are open, every wait_for_modal resolves with the first input

next meadow
#

cause it doesnt happen every time. but it does happen a lot

quasi copper
#

@faint jacinth do you know if the lib times out waiting for modals?

#

I'm not familiar enough with the internals to know off the top of my head

faint jacinth
#

modals never timeout by default

#

its how they're implemented in discord

next meadow
#

oh it all makes sense now

#

okay ill add the custom_id randomness later

#

almost feels like that should be handled internally

faint jacinth
#

not quite
there's a lot of ambiguity with that

next meadow
#

yeah true. maybe not with buttons

faint jacinth
#

plus, its useful to have modals that persist after a reboot

next meadow
#

or not randomness. ig ill just use the timestamp