Pycord-Development / pycord

Pycord is a modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python
https://docs.pycord.dev
MIT License
2.71k stars 457 forks source link

Role object converted to str in member.add_roles() #730

Closed KosmicAnomaly closed 2 years ago

KosmicAnomaly commented 2 years ago

Summary

Role object converted to str

Reproduction Steps

Passed a role object into member.add_roles()

Minimal Reproducible Code

roleObj = message.guild.get_role(someAwesomeInteger) or None
if roleObj is not None:
    await message.author.add_roles(roleObj, "Adding a role")

Expected Results

Add the role to the member like normal

Actual Results

Ignoring exception in on_message Traceback (most recent call last): File "C:\Users\ree\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 352, in _run_event await coro(*args, **kwargs) File "C:\Users\ree\Desktop\Code\DiscordBots\BlackHole\Modules\Fun\Leveling.py", line 478, in on_message await message.author.add_roles(roleObj, "Adding a role") File "C:\Users\ree\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\member.py", line 950, in add_roles await req(guild_id, user_id, role.id, reason=reason) AttributeError: 'str' object has no attribute 'id'

Intents

discord.Intents.all()

System Information

Checklist

Additional Context

No response

Makiyu-py commented 2 years ago

Since add_roles can take up multiple Snowflake objects, my guess is that it misinterpreted your reason as a snowflake object which gave that error. A simple fix to this is to make your reason a kwarg (i.e. await message.author.add_roles(roleObj, reason="Adding a role")).

KosmicAnomaly commented 2 years ago

Since add_roles can take up multiple Snowflake objects, my guess is that it misinterpreted your reason as a snowflake object which gave that error. A simple fix to this is to make your reason a kwarg (i.e. await message.author.add_roles(roleObj, reason="Adding a role")).

Yep that ended up being the issue, can't believe I missed that. Thanks! 😅