Handle responding to interactions in help formatter for hybrids #6724

Merged
Evanroby merged 6 commits from sendhelp-hybrid into V3/develop 2026-05-23 08:25:15 +02:00
Evanroby commented 2026-04-01 16:23:30 +02:00 (Migrated from github.com)

Description of the changes

Fixes #5916

This PR fixes an issue when using ctx.send_help() in a hybrid command's slash command, it causes a timeout if the help menu is set to not use menus. We are simply sending with ctx.send() instead of destination.send() on first page when it's an interaction and bot does not send help through dms.

Have the changes in this PR been tested?

Yes

### Description of the changes Fixes #5916 This PR fixes an issue when using `ctx.send_help()` in a hybrid command's slash command, it causes a timeout if the help menu is set to not use menus. We are simply sending with `ctx.send()` instead of `destination.send()` on first page when it's an interaction and bot does not send help through dms. ### Have the changes in this PR been tested? <!-- Choose one (remove the line that doesn't apply): --> Yes <!-- If the question doesn't apply (for example, it's not a code change), choose Yes. Please respond to this question truthfully. We do not delay nor reject PRs based on the answer to this question but it allows to better review this PR. -->
karlsbjorn (Migrated from github.com) reviewed 2026-04-01 16:23:30 +02:00
karlsbjorn (Migrated from github.com) reviewed 2026-04-01 17:20:41 +02:00
karlsbjorn (Migrated from github.com) commented 2026-04-01 17:10:54 +02:00

This will just have the bot be in an infinite thinking state since defer expects another interaction response, which is never provided in the case of a DM. It's better to just directly respond with an ephemeral message saying that the bot sent a DM.

This will just have the bot be in an infinite `thinking` state since defer expects another interaction response, which is never provided in the case of a DM. It's better to just directly respond with an ephemeral message saying that the bot sent a DM.
Evanroby commented 2026-04-01 17:43:33 +02:00 (Migrated from github.com)

Both fixes implemented, let me know if there's more !

Both fixes implemented, let me know if there's more !
Jackenmen (Migrated from github.com) requested changes 2026-05-22 06:32:38 +02:00
@ -907,8 +908,12 @@ class RedHelpFormatter(HelpFormatterABC):
)
else:
messages.append(msg)
Jackenmen (Migrated from github.com) commented 2026-05-22 06:19:00 +02:00

This seems simpler / avoids a conditional in every iteration and having to use enumerate():

            page_destination = ctx if ctx.interaction and not use_DMs else destination
            for page in pages:
                try:
                    if embed:
                        msg = await page_destination.send(embed=page)
                    else:
                        msg = await page_destination.send(page)
                except discord.Forbidden:
                    return await ctx.send(
                        _(
                            "I couldn't send the help message to you in DM. "
                            "Either you blocked me or you disabled DMs in this server."
                        )
                    )
                else:
                    messages.append(msg)
                    page_destination = destination

By the way, I want to note that when there are fewer than 6 pages, we could theoretically use ctx.send() because aside from the interaction response, it can send up to 5 follow-up responses. I'm not actually suggesting doing that here because it would need further discussion, but I just thought it was interesting.

This seems simpler / avoids a conditional in every iteration and having to use `enumerate()`: ```suggestion page_destination = ctx if ctx.interaction and not use_DMs else destination for page in pages: try: if embed: msg = await page_destination.send(embed=page) else: msg = await page_destination.send(page) except discord.Forbidden: return await ctx.send( _( "I couldn't send the help message to you in DM. " "Either you blocked me or you disabled DMs in this server." ) ) else: messages.append(msg) page_destination = destination ``` --- By the way, I want to note that when there are fewer than 6 pages, we could _theoretically_ use `ctx.send()` because aside from the interaction response, it can send up to 5 follow-up responses. I'm not actually suggesting doing that here because it would need further discussion, but I just thought it was interesting.
Jackenmen (Migrated from github.com) commented 2026-05-22 06:29:12 +02:00

Considering that the command can use await ctx.send_help() after doing something else first, this should be a more universal solution.

Specficially, this will work better in case the interaction is expired (in which case, this will ensure the message is sent to the channel rather than as a response) or if the user has already responded to the interaction (in which case, this will ensure the message is sent through an interaction follow-up):

                await ctx.send(
                    _("I have sent the help message to your DMs."), ephemeral=True
                )
Considering that the command can use `await ctx.send_help()` after doing something else first, this should be a more universal solution. Specficially, this will work better in case the interaction is expired (in which case, this will ensure the message is sent to the channel rather than as a response) *or* if the user has already responded to the interaction (in which case, this will ensure the message is sent through an interaction follow-up): ```suggestion await ctx.send( _("I have sent the help message to your DMs."), ephemeral=True ) ```
Evanroby commented 2026-05-22 06:41:43 +02:00 (Migrated from github.com)

Updated files to match your suggestions !

Updated files to match your suggestions !
Jackenmen (Migrated from github.com) reviewed 2026-05-22 06:45:25 +02:00
@ -907,8 +908,12 @@ class RedHelpFormatter(HelpFormatterABC):
)
Jackenmen (Migrated from github.com) commented 2026-05-22 06:45:25 +02:00
                await ctx.send(_("I have sent the help message to your DMs."), ephemeral=True)
```suggestion await ctx.send(_("I have sent the help message to your DMs."), ephemeral=True) ```
Jackenmen (Migrated from github.com) reviewed 2026-05-23 08:23:23 +02:00
@ -907,8 +908,12 @@ class RedHelpFormatter(HelpFormatterABC):
)
Jackenmen (Migrated from github.com) commented 2026-05-23 08:23:23 +02:00

These ifs have a common condition:

            if use_DMs:
                if ctx.interaction:
                    await ctx.send(_("I have sent the help message to your DMs."), ephemeral=True)
                elif help_settings.use_tick:
                    await ctx.tick()
These `if`s have a common condition: ```suggestion if use_DMs: if ctx.interaction: await ctx.send(_("I have sent the help message to your DMs."), ephemeral=True) elif help_settings.use_tick: await ctx.tick() ```
Jackenmen (Migrated from github.com) approved these changes 2026-05-23 08:23:33 +02:00
Sign in to join this conversation.
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!6724
No description provided.