Commands Used in Threads as User-Installed App #6501

Closed
opened 2025-01-03 07:12:24 +01:00 by SomewhatDamaged · 3 comments
SomewhatDamaged commented 2025-01-03 07:12:24 +01:00 (Migrated from github.com)

What Red version are you using?

3.5.14

What were you trying to do?

Receive a command.

Context:
Installed as a user app
Not present on server
Command run in a thread (cannot replicate what is causing this, permission wise, but a user can trigger it every time)

What did you expect to happen?

Bot receives command, processes it as normal and passes it to the cog.

What actually happened?

Function doesn't get called. Following appears in Red's log after a few minutes:

[2025-01-03 16:13:18] [ERROR] asyncio: Task exception was never retrieved
future: <Task finished name='CommandTree-invoker' coro=<CommandTree._from_interaction.<locals>.wrapper() done, defined at /home/gel/sourcebot/lib/python3.11/site-packages/discord/app_commands/tree.py:1149> exception=AttributeError("'NoneType' object has no attribute 'id'")>
Traceback (most recent call last):
  File "/home/gel/sourcebot/lib/python3.11/site-packages/discord/app_commands/tree.py", line 1151, in wrapper
    await self._call(interaction)
  File "/home/gel/sourcebot/lib/python3.11/site-packages/discord/app_commands/tree.py", line 1272, in _call
    if not await self.interaction_check(interaction):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gel/sourcebot/lib/python3.11/site-packages/redbot/core/tree.py", line 361, in interaction_check
    if not (await self.client.ignored_channel_or_guild(interaction)):
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gel/sourcebot/lib/python3.11/site-packages/redbot/core/bot.py", line 920, in ignored_channel_or_guild
    chann_ignored = await self._ignored_cache.get_ignored_channel(channel)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gel/sourcebot/lib/python3.11/site-packages/redbot/core/_settings_caches.py", line 169, in get_ignored_channel
    cid: int = channel.id
               ^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'id'

How can we reproduce this error?

I cannot replicate this myself, though the user who keeps having the problem can reliably trigger it on servers (and they aren't able to get the permissions list for them, though they are trying to contact an admin to do so).

Anything else?

What it looks like is your code here is running the check as if the bot was present on the server (which it isn't).

Then this check attempts to get the parent channel (which isn't available to the bot because it is a user-installed-app), and then tries to call that channel's (None) attributes.

There really can't be any checks for ignored (by the bot) channels like this, since it isn't on that server for anyone to run the command to lock channels.

### What Red version are you using? 3.5.14 ### What were you trying to do? Receive a command. Context: Installed as a user app Not present on server Command run in a thread (cannot replicate what is causing this, permission wise, but a user can trigger it every time) ### What did you expect to happen? Bot receives command, processes it as normal and passes it to the cog. ### What actually happened? Function doesn't get called. Following appears in Red's log after a few minutes: ``` [2025-01-03 16:13:18] [ERROR] asyncio: Task exception was never retrieved future: <Task finished name='CommandTree-invoker' coro=<CommandTree._from_interaction.<locals>.wrapper() done, defined at /home/gel/sourcebot/lib/python3.11/site-packages/discord/app_commands/tree.py:1149> exception=AttributeError("'NoneType' object has no attribute 'id'")> Traceback (most recent call last): File "/home/gel/sourcebot/lib/python3.11/site-packages/discord/app_commands/tree.py", line 1151, in wrapper await self._call(interaction) File "/home/gel/sourcebot/lib/python3.11/site-packages/discord/app_commands/tree.py", line 1272, in _call if not await self.interaction_check(interaction): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/gel/sourcebot/lib/python3.11/site-packages/redbot/core/tree.py", line 361, in interaction_check if not (await self.client.ignored_channel_or_guild(interaction)): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/gel/sourcebot/lib/python3.11/site-packages/redbot/core/bot.py", line 920, in ignored_channel_or_guild chann_ignored = await self._ignored_cache.get_ignored_channel(channel) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/gel/sourcebot/lib/python3.11/site-packages/redbot/core/_settings_caches.py", line 169, in get_ignored_channel cid: int = channel.id ^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'id' ``` ### How can we reproduce this error? I cannot replicate this myself, though the user who keeps having the problem can reliably trigger it on servers (and they aren't able to get the permissions list for them, though they are trying to contact an admin to do so). ### Anything else? What it looks like is your code [here](https://github.com/Cog-Creators/Red-DiscordBot/blob/cd0e8750c12a29690837937d989da26375f41ce5/redbot/core/tree.py#L355-L374) is running the check as if the bot was present on the server (which it isn't). Then [this check](https://github.com/Cog-Creators/Red-DiscordBot/blob/cd0e8750c12a29690837937d989da26375f41ce5/redbot/core/bot.py#L913-L920) attempts to get the parent channel (which isn't available to the bot because it is a user-installed-app), and then tries to call that channel's (`None`) attributes. There really can't be any checks for ignored (by the bot) channels like this, since it isn't on that server for anyone to run the command to lock channels.
Flame442 commented 2025-01-04 00:10:01 +01:00 (Migrated from github.com)

As the bot owner, you likely bypassed the failing check.

For user-installed app commands used in threads, channel.parent is None. channel.parent_id appears to still work fine. Not sure how easy it would be with the rest of the code to use the ID instead of the object, but that may be the necessary fix.

github.com/Cog-Creators/Red-DiscordBot@cd0e8750c1/redbot/core/bot.py (L913-L918)

As the bot owner, you likely bypassed the failing check. For user-installed app commands used in threads, `channel.parent` is `None`. `channel.parent_id` appears to still work fine. Not sure how easy it would be with the rest of the code to use the ID instead of the object, but that may be the necessary fix. https://github.com/Cog-Creators/Red-DiscordBot/blob/cd0e8750c12a29690837937d989da26375f41ce5/redbot/core/bot.py#L913-L918
Kowlin commented 2025-01-04 00:30:19 +01:00 (Migrated from github.com)

Sounds doable if we do an isinstance check for discord.Interaction on ctx, and then we bypass the entirety of setting the context for the thread, since it doesn't make sense to do there. At least that's what my sleep depraved brain is on about now. Not sure how well it would work in practice.

Sounds doable if we do an ``isinstance`` check for discord.Interaction on ``ctx``, and then we bypass the entirety of setting the context for the thread, since it doesn't make sense to do there. At least that's what my sleep depraved brain is on about now. Not sure how well it would work in practice.
Flame442 commented 2025-01-04 20:43:11 +01:00 (Migrated from github.com)

For app commands that are guild installed, it still makes sense to have them respect the ignored channel rules. For app commands that are user installed, we could technically have them continue to respect those rules by using the ID, but the UX around ignored channels gets fuzzy in that context.

For app commands that are guild installed, it still makes sense to have them respect the ignored channel rules. For app commands that are user installed, we could technically have them continue to respect those rules by using the ID, but the UX around ignored channels gets fuzzy in that context.
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#6501
No description provided.