botmanager.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:JshBot-legacy 作者: jkchen2 项目源码 文件源码
def update_color_role(server_id, user_id, color):

    # Get server and user, along with role name
    server = discord.utils.get(client.servers, id=server_id)
    user = discord.utils.get(server.members, id=user_id)
    role_name = 'c_{}'.format(user_id)

    # Remove role if it exists, even if it's not used
    current_role = discord.utils.get(user.roles, name=role_name)
    if current_role is not None:
        await client.delete_role(server, current_role)
    if color is not None: # Assign new color
        new_role = await client.create_role(
            server,
            colour=discord.Color(color),
            name=role_name)

        # Finally, assign new role to user
        await client.add_roles(user, new_role)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号