#button components not staying persistent when in while loop?

1 messages · Page 1 of 1 (latest)

naive surge
#

I have this code designed to make a somewhat interactive menu that can end pretty quickly.

while True:
    try:
        context = await ctx.bot.wait_for_component(
            check=lambda x: x.ctx.author.id == ctx.author.id,
            messages=message,
            timeout=30,
        )

        context = context.ctx
        if context.custom_id == f"{ctx.guild.id}|staff|dropdown":
            if not context.values:
                return

            selection = context.values[-1]

            match selection:
                pass # selection cases here
        elif context.custom_id == f"{context.guild_id}|staff|ban_toggle":
            reason = Modal(
                ParagraphText(
                    label="Reason",
                    custom_id="ban_reason",
                    placeholder="No reason provided.",
                    max_length=200,
                    required=False,
                ),
                title=f"{'Unban' if is_banned else 'Ban'} {user_info.name}",
            )
            await context.send_modal(reason)
            reason_ctx: ModalContext = await ctx.bot.wait_for_modal(
                reason
            ) # once sending the modal, if it is sent or cancelled i cant click it again at all

            # rest of code here

        elif (
            context.custom_id == f"{context.guild_id}|staff|add_alt_account"
            or context.custom_id
            == f"{context.guild_id}|staff|remove_alt_account"
        ):
            is_adding = "add_alt_account" in context.custom_id
            username_form = Modal(
                ShortText(
                    label="Alternative Account Username",
                    custom_id="username",
                    placeholder="Enter a Roblox username.",
                    min_length=3,
                    max_length=20,
                    required=True,
                ),
                title=f"{'Add' if is_adding else 'Remove'} Alt Account",
            )

            while (
                context.custom_id == f"{context.guild_id}|staff|add_alt_account"
            ) or (
                context.custom_id
                == f"{context.guild_id}|staff|remove_alt_account"
            ): # This modal button here is not persistant at all despite trying this while loop.
                await context.send_modal(username_form)
                username_ctx: ModalContext = await ctx.bot.wait_for_modal(
                    username_form
                )
                
            # rest of code here

You can see i tried directly using it with the ban_toggle component, then tried a while condition on the add_alt_account/remove_alt_account components, none working as expected. Once i click the component and the modal first sends, even if i cancel the modal, the component is unusable

anyone got an idea to fix this? I was going to try using event listeners but it just isn't possible without making a lot of unnecessary requests which i'd like to avoid

jolly shadowBOT
#

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