AttributeError: 'NoneType' object has no attribute 'permissions'
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
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
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.rolesis actually defined asself._rolesin discord/member.py? Multiple timesself.rolesis referenced but it doesn't seem to exist, unless I'm wrong
roles is a property in Member
Checking the source, I think g.default_role in member.py line 495 somehow returned None. Could be about intents.
Add guilds intent to your bot, maybe You bot can't access the guild information.