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

Accessing server-specific attributes of discord.Member with user apps causes an exception #2515

Closed
3 tasks done
ToothyDev opened this issue Aug 5, 2024 · 1 comment · Fixed by #2573
Closed
3 tasks done
Assignees
Labels
bug Something isn't working Failing API Reflection priority: high High Priority status: todo This issue needs work
Milestone

Comments

@ToothyDev
Copy link

Summary

If you access server-specific (aka Member related stuff) with a user-installed app, python throws an exception trying to get the member object. I also found that member.display_avatar in particular throws an error only if a server-specific avatar has been set.

Reproduction Steps

Make a user app
Install it on your account
Make a user command (context menu > user)
Try to print member.roles, member.top_role, member.display_avatar (if set) etc., anything Member-specific
See the console for the exception

Minimal Reproducible Code

@discord.user_command()
async def bugrepro(self, ctx: discord.ApplicationContext, member: discord.Member):
    print(member.roles)

Expected Results

Pycord handles the case of a user-installed app automatically, and simply returns None for e.g. member.roles, or the global avatar in the case of member.display_avatar

Actual Results

Pycord seems to not handle this at all and throws an exception

Intents

all / not applicable, happens regardless of intents

System Information

  • Python v3.12.4-final
  • py-cord v2.6.None-final
  • aiohttp v3.9.5
  • system info: Windows 11 10.0.22631

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

Traceback for printing member.roles (project path replaced with ...)

Ignoring exception in command bugrepro:
Traceback (most recent call last):
  File "...venv\Lib\site-packages\discord\commands\core.py", line 138, in wrapped
    ret = await coro(arg)
          ^^^^^^^^^^^^^^^
  File "...venv\Lib\site-packages\discord\commands\core.py", line 1796, in _invoke
    await self.callback(self.cog, ctx, target)
  File "...cogs\user_commands.py", line 30, in bugrepro
    print(member.roles)
          ^^^^^^^^^^^^
  File "...venv\Lib\site-packages\discord\member.py", line 562, in roles
    role = g.get_role(role_id)
           ^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get_role'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "...venv\Lib\site-packages\discord\bot.py", line 1137, in invoke_application_command
    await ctx.command.invoke(ctx)
  File "...venv\Lib\site-packages\discord\commands\core.py", line 435, in invoke
    await injected(ctx)
  File "...venv\Lib\site-packages\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 'get_role'
@ToothyDev ToothyDev added the unconfirmed bug A bug report that needs triaging label Aug 5, 2024
@ToothyDev ToothyDev changed the title Accessing server-specific attributes with user apps causes an exception Accessing server-specific attributes of discord.Member with user apps causes an exception Aug 5, 2024
@Lulalaby Lulalaby added bug Something isn't working priority: high High Priority status: todo This issue needs work Failing API Reflection and removed unconfirmed bug A bug report that needs triaging labels Aug 5, 2024
@Lulalaby Lulalaby added this to the v2.7 milestone Aug 5, 2024
@Dorukyum
Copy link
Member

Dorukyum commented Aug 5, 2024

Seems to happen due to g being None, could be solved by adding a simple check.

@plun1331 plun1331 linked a pull request Sep 26, 2024 that will close this issue
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Failing API Reflection priority: high High Priority status: todo This issue needs work
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants