You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When inviting bot only with applications.commands scope has_permissions will fail due to an attribute error.
Reproduction Steps
Register a command with @has_permissions(administrator=True) for example.
Invite the bot only with applications.commands scope.
Try to execute the command.
See how you get an attribute error in the console.
AttributeError: 'PartialMessageable' object has no attribute 'permissions_for'
Minimal Reproducible Code
importdiscordfromdiscord.ext.commandsimporthas_permissionsbot=discord.Bot()
@bot.eventasyncdefon_ready():
print(f"We have logged in as {bot.user}")
@has_permissions(administrator=True)@bot.slash_command(guild_ids=[guild_id])asyncdefhello(ctx):
awaitctx.respond("Hello!")
bot.run("TOKEN")
Expected Results
We should get a more telling error message that the channel was not cached and for that reason we cant check permissions.
Actual Results
We get an error
AttributeError: 'PartialMessageable' object has no attribute 'permissions_for'
Since we did not get an GUILD_CREATE event for the guild because it was not invited with the bot scope
Traceback:
Ignoring exception in on_interaction
Traceback (most recent call last):
File "C:\Users\Mihito\PycharmProjects\pythonProject\venv\lib\site-packages\discord\client.py", line 378, in _run_event
await coro(*args, **kwargs)
File "C:\Users\Mihito\PycharmProjects\pythonProject\venv\lib\site-packages\discord\bot.py", line 1167, in on_interaction
await self.process_application_commands(interaction)
File "C:\Users\Mihito\PycharmProjects\pythonProject\venv\lib\site-packages\discord\bot.py", line 848, in process_application_commands
await self.invoke_application_command(ctx)
File "C:\Users\Mihito\PycharmProjects\pythonProject\venv\lib\site-packages\discord\bot.py", line 1114, in invoke_application_command
await ctx.command.invoke(ctx)
File "C:\Users\Mihito\PycharmProjects\pythonProject\venv\lib\site-packages\discord\commands\core.py", line 372, in invoke
await self.prepare(ctx)
File "C:\Users\Mihito\PycharmProjects\pythonProject\venv\lib\site-packages\discord\commands\core.py", line 292, in prepare
if not await self.can_run(ctx):
File "C:\Users\Mihito\PycharmProjects\pythonProject\venv\lib\site-packages\discord\commands\core.py", line 400, in can_run
return await async_all(predicate(ctx) for predicate in predicates) # type: ignore
File "C:\Users\Mihito\PycharmProjects\pythonProject\venv\lib\site-packages\discord\utils.py", line 699, in async_all
for elem in gen:
File "C:\Users\Mihito\PycharmProjects\pythonProject\venv\lib\site-packages\discord\commands\core.py", line 400, in
return await async_all(predicate(ctx) for predicate in predicates) # type: ignore
File "C:\Users\Mihito\PycharmProjects\pythonProject\venv\lib\site-packages\discord\ext\commands\core.py", line 2129, in predicate
permissions = ctx.channel.permissions_for(ctx.author) # type: ignore
AttributeError: 'PartialMessageable' object has no attribute 'permissions_for'
Intents
default
System Information
Python v3.9.13-final
py-cord v2.4.1-final
aiohttp v3.8.4
system info: Windows 10 10.0.19045
Checklist
I have searched the open issues for duplicates.
I have shown the entire traceback, if possible.
I have removed my token from display, if visible.
Additional Context
No response
The text was updated successfully, but these errors were encountered:
Inviting bots only with app command scope is meant for http interaction bots normally.
While this is true in my opinion there should still be a type check.
The type hints explicitly say that this can be a PartialMessagable.
Of course its a very niche problem but imo still worth to fix.
Summary
When inviting bot only with applications.commands scope has_permissions will fail due to an attribute error.
Reproduction Steps
Register a command with @has_permissions(administrator=True) for example.
Invite the bot only with applications.commands scope.
Try to execute the command.
See how you get an attribute error in the console.
AttributeError: 'PartialMessageable' object has no attribute 'permissions_for'
Minimal Reproducible Code
Expected Results
We should get a more telling error message that the channel was not cached and for that reason we cant check permissions.
Actual Results
We get an error
AttributeError: 'PartialMessageable' object has no attribute 'permissions_for'
Since we did not get an GUILD_CREATE event for the guild because it was not invited with the bot scope
Traceback:
Ignoring exception in on_interaction
Traceback (most recent call last):
File "C:\Users\Mihito\PycharmProjects\pythonProject\venv\lib\site-packages\discord\client.py", line 378, in _run_event
await coro(*args, **kwargs)
File "C:\Users\Mihito\PycharmProjects\pythonProject\venv\lib\site-packages\discord\bot.py", line 1167, in on_interaction
await self.process_application_commands(interaction)
File "C:\Users\Mihito\PycharmProjects\pythonProject\venv\lib\site-packages\discord\bot.py", line 848, in process_application_commands
await self.invoke_application_command(ctx)
File "C:\Users\Mihito\PycharmProjects\pythonProject\venv\lib\site-packages\discord\bot.py", line 1114, in invoke_application_command
await ctx.command.invoke(ctx)
File "C:\Users\Mihito\PycharmProjects\pythonProject\venv\lib\site-packages\discord\commands\core.py", line 372, in invoke
await self.prepare(ctx)
File "C:\Users\Mihito\PycharmProjects\pythonProject\venv\lib\site-packages\discord\commands\core.py", line 292, in prepare
if not await self.can_run(ctx):
File "C:\Users\Mihito\PycharmProjects\pythonProject\venv\lib\site-packages\discord\commands\core.py", line 400, in can_run
return await async_all(predicate(ctx) for predicate in predicates) # type: ignore
File "C:\Users\Mihito\PycharmProjects\pythonProject\venv\lib\site-packages\discord\utils.py", line 699, in async_all
for elem in gen:
File "C:\Users\Mihito\PycharmProjects\pythonProject\venv\lib\site-packages\discord\commands\core.py", line 400, in
return await async_all(predicate(ctx) for predicate in predicates) # type: ignore
File "C:\Users\Mihito\PycharmProjects\pythonProject\venv\lib\site-packages\discord\ext\commands\core.py", line 2129, in predicate
permissions = ctx.channel.permissions_for(ctx.author) # type: ignore
AttributeError: 'PartialMessageable' object has no attribute 'permissions_for'
Intents
default
System Information
Checklist
Additional Context
No response
The text was updated successfully, but these errors were encountered: