Skip to content

Implement defer#770

Open
MattyTheHacker wants to merge 3 commits into
mainfrom
fix-add-to-channel
Open

Implement defer#770
MattyTheHacker wants to merge 3 commits into
mainfrom
fix-add-to-channel

Conversation

@MattyTheHacker
Copy link
Copy Markdown
Member

Unable to reproduce the 403 error but it has since started timing out so added defer bits.

@MattyTheHacker MattyTheHacker self-assigned this May 15, 2026
Copilot AI review requested due to automatic review settings May 15, 2026 16:33
@MattyTheHacker MattyTheHacker added bug Something isn't working sync Request bots to automatically keep this PR up to date with it's base branch labels May 15, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the “add user/role to channel/thread” slash commands to defer their interaction responses, aiming to prevent Discord interaction timeouts during slower operations.

Changes:

  • Added ctx.defer() to /add-users-to-channel and /add-role-to-channel.
  • Switched success responses from ctx.respond(...) to ctx.followup.send(...) to align with deferred interactions.
  • Simplified channel/thread type checking with a tuple-based isinstance call.
Comments suppressed due to low confidence (2)

cogs/add_users_to_threads_and_channels.py:293

  • await ctx.defer() is called before validation branches that use self.command_send_error(...). command_send_error ultimately calls interaction.respond(...) (utils/tex_bot_base_cog.py), which will fail once the interaction has already been deferred/responded. In this function that happens in the role_to_add is None path. Move the defer() call to after all early-return validations (or update send_error/command_send_error to use interaction.followup.send when the interaction response is already done).
        await ctx.defer()

        main_guild: discord.Guild = ctx.bot.main_guild

        try:
            role_id: int = int(role_id_str)
        except ValueError:
            logger.debug("Role ID: %s is not a valid ID.", role_id_str)
            await ctx.respond(content=f"The role: {role_id_str} is not valid.")
            return

        role_to_add: discord.Role | None = discord.utils.get(main_guild.roles, id=role_id)

        if role_to_add is None:
            await self.command_send_error(
                ctx, message=f"The role: <@{role_id}> is not valid or couldn't be found."
            )
            return

cogs/add_users_to_threads_and_channels.py:277

  • await ctx.defer() here should likely be await ctx.defer(ephemeral=True) since the command’s user-facing responses are sent ephemerally. Otherwise the deferred "thinking" indicator is visible to everyone in the channel/thread.
        await ctx.defer()


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cogs/add_users_to_threads_and_channels.py Outdated
MattyTheHacker and others added 2 commits May 15, 2026 17:39
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Matty Widdop <18513864+MattyTheHacker@users.noreply.github.com>
Signed-off-by: Matty Widdop <18513864+MattyTheHacker@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working sync Request bots to automatically keep this PR up to date with it's base branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants