简体   繁体   English

如何在 pycord 中为用户分配角色?

[英]How do you assign a role to a user in pycord?

I have a discord bot that needs to add someone to the ban watch list, which is a role.我有一个 discord 机器人,需要将某人添加到禁止监视列表中,这是一个角色。 But so far, all I can find are discord.py solutions, and since discord.py is discontinued, I use pycord instead.但到目前为止,我能找到的只是 discord.py 解决方案,并且由于 discord.py 已停产,我改用 pycord。 The bot has full admin privileges, so those are no worry.该机器人具有完全的管理员权限,所以不用担心。

dmchannel = await user.create_dm()
dmchannel.send(f"<@{user.id}> You have been put on the ban watch list! Be careful, you could be banned soon.")
# Add the role here

How would I manage to do this?我将如何做到这一点?

Pycord is now not much different from discord.py. Pycord现在与 discord.py 没有太大区别。
So, you can use something like this:所以,你可以使用这样的东西:

member = something  # specify member here
role = something  # specify role here
await member.add_roles(role)

you can get the role using discord utils, then using member.add_roles()您可以使用 discord 工具获取角色,然后使用member.add_roles()

member = #member
role = discord.utils.get(ctx.guild.roles, name=#role name)
member.add_roles(role)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM