Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Commands Used in Threads as User-Installed App #6501

Open
SomewhatDamaged opened this issue Jan 3, 2025 · 3 comments · May be fixed by #6503
Open

Commands Used in Threads as User-Installed App #6501

SomewhatDamaged opened this issue Jan 3, 2025 · 3 comments · May be fixed by #6503
Assignees
Labels
Status: In Progress There's a PR open to deal with this, or an org member is working on this internally Type: Bug Unexpected behavior, result, or exception. In case of PRs, it is a fix for the foregoing.

Comments

@SomewhatDamaged
Copy link

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.

@SomewhatDamaged SomewhatDamaged added the Type: Bug Unexpected behavior, result, or exception. In case of PRs, it is a fix for the foregoing. label Jan 3, 2025
@github-actions github-actions bot added the Status: Needs Triage This has not been labeled or discussed for handling yet. label Jan 3, 2025
@Kowlin Kowlin added Status: Accepted We want this and removed Status: Needs Triage This has not been labeled or discussed for handling yet. labels Jan 3, 2025
@Kowlin Kowlin self-assigned this Jan 3, 2025
@Flame442
Copy link
Member

Flame442 commented Jan 3, 2025

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.

if isinstance(ctx.channel, discord.Thread):
channel = ctx.channel.parent
thread = ctx.channel
else:
channel = ctx.channel
thread = None

@Kowlin
Copy link
Member

Kowlin commented Jan 3, 2025

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
Copy link
Member

Flame442 commented Jan 4, 2025

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.

@Kowlin Kowlin linked a pull request Jan 6, 2025 that will close this issue
@Kowlin Kowlin added Status: In Progress There's a PR open to deal with this, or an org member is working on this internally and removed Status: Accepted We want this labels Jan 6, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Status: In Progress There's a PR open to deal with this, or an org member is working on this internally Type: Bug Unexpected behavior, result, or exception. In case of PRs, it is a fix for the foregoing.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants