pycord icon indicating copy to clipboard operation
pycord copied to clipboard

AttributeError: 'NoneType' object has no attribute 'permissions'

Open Luckolite opened this issue 4 years ago • 4 comments

Summary

When checking the authors guild_permissions it raises an error

Reproduction Steps

add a basic slash command, and within it have a permission check

Minimal Reproducible Code

bot = commands.Bot(intents=discord.Intents(messages=True, members=True))

@bot.slash_command(name="enable", description="Enables filtering phishing scams")
async def enable(
    ctx, action: Option(
        str, "Action To Take",
        choices=["Delete", "Delete & Timeout","Delete & Ban"]
    )
):
    if not ctx.author.guild_permissions.administrator:
        return await ctx.respond("You need administrator permissions to run this", ephemeral=True)
    # unreachable

Expected Results

it correctly returns the bool for whether or not they have such permission

Actual Results

Traceback (most recent call last):
  File "/home/luck/.local/lib/python3.8/site-packages/discord/commands/core.py", line 110, in wrapped
    ret = await coro(arg)
  File "/home/luck/.local/lib/python3.8/site-packages/discord/commands/core.py", line 766, in _invoke
    await self.callback(ctx, **kwargs)
  File "main.py", line 150, in enable
    if not ctx.author.guild_permissions.administrator:
  File "/home/luck/.local/lib/python3.8/site-packages/discord/member.py", line 609, in guild_permissions
    base.value |= r.permissions.value
AttributeError: 'NoneType' object has no attribute 'permissions'

Intents

messages, members

System Information

  • Python v3.8.10-final
  • py-cord v2.0.0-beta
    • py-cord pkg_resources: v2.0.0b3
  • aiohttp v3.6.3
  • system info: Linux 5.13.0-27-generic #29~20.04.1-Ubuntu SMP Fri Jan 14 00:32:30 UTC 2022

Checklist

  • [X] I have searched the open issues for duplicates.
  • [X] I have shown the entire traceback, if possible.
  • [X] I have removed my token from display, if visible.

Additional Context

No response

Luckolite avatar Feb 05 '22 20:02 Luckolite

sorry If I'm wrong, I am a noob and don't know how to check for myself by forking, but is it not just because self.roles is actually defined as self._roles in discord/member.py? Multiple times self.roles is referenced but it doesn't seem to exist, unless I'm wrong

eggnogdev avatar Feb 06 '22 03:02 eggnogdev

sorry If I'm wrong, I am a noob and don't know how to check for myself by forking, but is it not just because self.roles is actually defined as self._roles in discord/member.py? Multiple times self.roles is referenced but it doesn't seem to exist, unless I'm wrong

roles is a property in Member

plun1331 avatar Feb 06 '22 03:02 plun1331

Checking the source, I think g.default_role in member.py line 495 somehow returned None. Could be about intents.

Dorukyum avatar Feb 06 '22 10:02 Dorukyum

Add guilds intent to your bot, maybe You bot can't access the guild information.

ephemeral8997 avatar Feb 09 '22 04:02 ephemeral8997