如何让某人在Discord.py Rewrite中扮演角色

问题描述 投票:0回答:1

我正在为我的不和谐服务器创建一个机器人。当用户说出特定命令时,机器人会给他们一个角色

我已经尝试在其他stackoverflow问题中查找其他代码,并查看了Discord.Py Rewrite文档。同样对于视频,它们也不是discord.py rewrite

@@ bot.command()

异步def募集人(ctx):

user = ctx.message.author

role = discord.utils.get(user.guild.roles, name="Recruit")

await user.guild.roles(role)

我希望我可以学习如何编码机器人所扮演的角色。

python discord discord.py-rewrite
1个回答
0
投票
@client.command()
    async def role(ctx, member:discord.Member, role: discord.Role): #pass user and role
        if role in member.roles: #checks all roles the member has
            await member.remove_roles(role) #removes the role
        else:
            await member.add_roles(role) #adds the role

在这种情况下,代码首先检查成员具有的所有角色中的指定角色。如果不存在,它将添加角色,如果已经存在,则将其删除。

© www.soinside.com 2019 - 2024. All rights reserved.