#commands.has_permissions() and DMs

1 messages · Page 1 of 1 (latest)

tender steeple
#

A slash command decorated with @commands.has_permissions() or @commands.bot_has_permissions() will raise

AttributeError: 'PartialMessageable' object has no attribute 'permissions_for' when it is invoked via DMs.

Does anyone know a nice way to conditionally apply these decorators so they only apply for commands invoked in a guild and not in DMs?

true yarrow
#

@guild_only() i believe

halcyon escarp
tender steeple
#

i assume it works self referentially for the bot user itself

true yarrow
#

its a check like the one in the title

tender steeple
#

I do use that decorator in combination with the decorators in the OP and still get the AttributeError

true yarrow
#

hmm

#

whats your pycord version?

tender steeple
#

@commands.guild_only()

#

2.0.0b7

true yarrow
#

try updating to master

#

or reinstall

tender steeple
tender steeple
# true yarrow try updating to master

ty this worked along with moving @commands.guild_only() closest to async def so it runs first before the permissions checks

last change I need to make is fixing this for when I want a permissions check in guild and not in DM for commands which are not guild only

true yarrow
#

oh yeah, i did forget to mention that decorator order matters

tender steeple
#

yeah no worries i figured that out, it used to work in earlier pycord unordered for some reason

tender steeple
#

to solve this for non guild only commands i used a check with predicate

async def check_view_read(ctx):
    '''
    Check and return if the bot has the View Channels
    and Read Message History channel permissions
    '''
    if isinstance(ctx.channel, PartialMessageable):
        return True

    permissions = ctx.channel.permissions_for(ctx.guild.get_member(ctx.bot.user.id))

    return permissions.view_channel and permissions.read_message_history

instead of @commands.bot_has_permissions()