Get a Discord Role by Id

牧云@^-^@ 提交于 2021-01-20 04:47:10

问题


I'm making a Discord bot but just ran into a problem.

I want to modify a role. A specific role. I know how to do that with edit_role, but I need to get the Role object to edit it. Now, that's the problem.

How do I get a Role object by the role's id? Or can I use the id in the Role argument?


回答1:


You can use discord.utils.get to loop through Guild.roles and get the one you're looking for:

from discord.utils import get

role_id = 123
role = get(guild.roles, id=role_id)



回答2:


You can simply use Guild.get_role(role_id) to get the role if you have the id.

role_id = 2134532534
role = my_server.get_role(role_id)


来源:https://stackoverflow.com/questions/52457916/get-a-discord-role-by-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!