Summary
When using a user-installed message command in a guild the bot is not present in, accessing ctx.author.guild_permissions raises an error
Reproduction Steps
Run the below code, user-install the bot and run the message command on a message in a guild the bot is not present in.
Minimal Reproducible Code
import os
from dotenv import load_dotenv
import discord
import logging
logging.basicConfig(level=logging.DEBUG)
load_dotenv()
TOKEN = os.getenv("TOKEN")
bot = discord.Bot()
@bot.message_command(
contexts={
discord.InteractionContextType.guild,
discord.InteractionContextType.bot_dm,
discord.InteractionContextType.private_channel,
},
integration_types={discord.IntegrationType.guild_install, discord.IntegrationType.user_install},
)
async def test_command(ctx: discord.ApplicationContext, message: discord.Message):
await ctx.defer(ephemeral=True)
await ctx.respond(f"{ctx.author.guild_permissions.administrator}")
@bot.listen()
async def on_ready():
logging.info(f"Logged in as {bot.user.name}")
bot.run(TOKEN)
Expected Results
ctx.author.guild_permissions.administrator being false or ctx.author.guild_permissions being missing.
Actual Results
An error, traceback:
Ignoring exception in command test_command:
Traceback (most recent call last):
File "C:\Users\Jérémie\Documents\GitHub\pycord\discord\commands\core.py", line 138, in wrapped
ret = await coro(arg)
^^^^^^^^^^^^^^^
File "C:\Users\Jérémie\Documents\GitHub\pycord\discord\commands\core.py", line 1904, in _invoke
await self.callback(ctx, target)
File "C:\Users\Jérémie\Documents\GitHub\pycord\thing.py", line 27, in test_command
await ctx.respond(f"{ctx.author.guild_permissions.administrator}")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Jérémie\Documents\GitHub\pycord\discord\member.py", line 706, in guild_permissions
base.value |= r.permissions.value
^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'permissions'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Jérémie\Documents\GitHub\pycord\discord\bot.py", line 1149, in invoke_application_command
await ctx.command.invoke(ctx)
File "C:\Users\Jérémie\Documents\GitHub\pycord\discord\commands\core.py", line 435, in invoke
await injected(ctx)
File "C:\Users\Jérémie\Documents\GitHub\pycord\discord\commands\core.py", line 146, in wrapped
raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: AttributeError: 'NoneType' object has no attribute 'permissions'
Intents
n/a
System Information
master
Checklist
Additional Context
No response
Summary
When using a user-installed message command in a guild the bot is not present in, accessing
ctx.author.guild_permissionsraises an errorReproduction Steps
Run the below code, user-install the bot and run the message command on a message in a guild the bot is not present in.
Minimal Reproducible Code
Expected Results
ctx.author.guild_permissions.administratorbeing false orctx.author.guild_permissionsbeing missing.Actual Results
An error, traceback:
Intents
n/a
System Information
master
Checklist
Additional Context
No response