Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

commands.bot_has_permissions doesn't work for slash or bridge commands in dms #1421

Closed
3 tasks done
Revnoplex opened this issue Jun 14, 2022 · 5 comments · Fixed by #1460
Closed
3 tasks done

commands.bot_has_permissions doesn't work for slash or bridge commands in dms #1421

Revnoplex opened this issue Jun 14, 2022 · 5 comments · Fixed by #1460
Labels
bug Something isn't working

Comments

@Revnoplex
Copy link
Contributor

Revnoplex commented Jun 14, 2022

Summary

bot_has_permissions works fine for prefix commands in dms but throws an error when using slash commands or bridge commands

Reproduction Steps

create a slash command or bridge command
note: this was in a cog (not sure if it occurs otherwise)
use the bot_has_permissions check
try running the command in dms

Minimal Reproducible Code

@commands.slash_command(name="test", description="Hello World")
@commands.bot_has_permissions(send_messages=True)
async def test(self, ctx):
    await ctx.respond("Hello World")

Expected Results

correctly invoke the command and not throw an error like a prefix command usually does.

Actual Results

throws an error from /lib-dir/ext/commands/core.py on line 2082

permissions = ctx.channel.permissions_for(me)  # type: ignore

AttributeError: 'PartialMessageable' object has no attribute 'permissions_for'.

Traceback:
  File "/bot-dir/venv/lib/python3.10/site-packages/discord/client.py", line 382, in _run_event
    await coro(*args, **kwargs)

  File "/bot-dir/venv/lib/python3.10/site-packages/discord/bot.py", line 1045, in on_interaction
    await self.process_application_commands(interaction)

  File "/bot-dir/venv/lib/python3.10/site-packages/discord/bot.py", line 737, in process_application_commands
    await self.invoke_application_command(ctx)

  File "/bot-dir/venv/lib/python3.10/site-packages/discord/bot.py", line 993, in invoke_application_command
    await ctx.command.invoke(ctx)

  File "/bot-dir/venv/lib/python3.10/site-packages/discord/commands/core.py", line 354, in invoke
    await self.prepare(ctx)

  File "/bot-dir/venv/lib/python3.10/site-packages/discord/commands/core.py", line 276, in prepare
    if not await self.can_run(ctx):

  File "/bot-dir/venv/lib/python3.10/site-packages/discord/commands/core.py", line 373, in can_run
    return await async_all(predicate(ctx) for predicate in predicates)  # type: ignore

  File "/bot-dir/venv/lib/python3.10/site-packages/discord/utils.py", line 562, in async_all
    for elem in gen:

  File "/bot-dir/venv/lib/python3.10/site-packages/discord/commands/core.py", line 373, in <genexpr>
    return await async_all(predicate(ctx) for predicate in predicates)  # type: ignore

  File "/bot-dir/venv/lib/python3.10/site-packages/discord/ext/commands/core.py", line 2082, in predicate
    permissions = ctx.channel.permissions_for(me)  # type: ignore

Intents

all

System Information

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

@Revnoplex Revnoplex added the unconfirmed bug A bug report that needs triaging label Jun 14, 2022
@Revnoplex
Copy link
Contributor Author

This appears to stem to another issue where dm channels will always appear as partial messagables

@Lulalaby Lulalaby linked a pull request Jun 30, 2022 that will close this issue
@Lulalaby Lulalaby added bug Something isn't working and removed unconfirmed bug A bug report that needs triaging labels Jun 30, 2022
@Revnoplex
Copy link
Contributor Author

the issue didn't fix its now occuring on line 2119!

Traceback:
  File "/bot-dir/venv/lib/python3.10/site-packages/discord/client.py", line 382, in _run_event
    await coro(*args, **kwargs)

  File "/bot-dir/venv/lib/python3.10/site-packages/discord/bot.py", line 1044, in on_interaction
    await self.process_application_commands(interaction)

  File "/bot-dir/venv/lib/python3.10/site-packages/discord/bot.py", line 736, in process_application_commands
    await self.invoke_application_command(ctx)

  File "/bot-dir/venv/lib/python3.10/site-packages/discord/bot.py", line 992, in invoke_application_command
    await ctx.command.invoke(ctx)

  File "/bot-dir/venv/lib/python3.10/site-packages/discord/commands/core.py", line 355, in invoke
    await self.prepare(ctx)

  File "/bot-dir/venv/lib/python3.10/site-packages/discord/commands/core.py", line 277, in prepare
    if not await self.can_run(ctx):

  File "/bot-dir/venv/lib/python3.10/site-packages/discord/commands/core.py", line 374, in can_run
    return await async_all(predicate(ctx) for predicate in predicates)  # type: ignore

  File "/bot-dir/venv/lib/python3.10/site-packages/discord/utils.py", line 562, in async_all
    for elem in gen:

  File "/bot-dir/venv/lib/python3.10/site-packages/discord/commands/core.py", line 374, in <genexpr>
    return await async_all(predicate(ctx) for predicate in predicates)  # type: ignore

  File "/bot-dir/venv/lib/python3.10/site-packages/discord/ext/commands/core.py", line 2119, in predicate
    permissions = ch.permissions_for(ctx.author)  # type: ignore

also environment changed slightly since full pycord release and 3.10.5

@Dorukyum
Copy link
Member

Dorukyum commented Jul 9, 2022

Why not use discord.default_permissions instead

@Revnoplex
Copy link
Contributor Author

does it work with bridge commands?

@Revnoplex
Copy link
Contributor Author

is there a bot_has_permissions equivalent?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants