【问题标题】:How to assign roles in discord.py latest version?如何在 discord.py 最新版本中分配角色?
【发布时间】:2020-04-08 12:43:43
【问题描述】:

我整天都在寻找这个,我似乎找不到为成员分配角色的正确方法。我尝试了几种分配角色的方法:

@client.command(pass_context=True)
async def claimrank(ctx, role: discord.Role):
    user = ctx.message.author
    await user.add_roles(role='Rookie')

和:

@client.command()
async def claimrank(member):
    role = get(member.guild.roles, name="Rookie")
    await member.add_roles(role)

更糟糕的是,通过这两种尝试,我都没有收到任何错误,但代码没有做任何事情。 请帮忙! 提前致谢。

【问题讨论】:

    标签: python python-3.x discord.py discord.py-rewrite


    【解决方案1】:

    我今天从最近的一个帖子中得到了这个。我会写代码,找原帖。

    @client.command(pass_context=True)
    async def addrole(ctx):
        user = ctx.message.author 
        role = 'role' #change the role here
        try:
            await user.add_roles(discord.utils.get(user.guild.roles, name=role)) 
        except Exception as e:
            await ctx.send('Cannot assign role. Error: ' + str(e))
    

    找到@Patrick Haugh 的原帖:Give and remove roles with a bot, Discord.py

    【讨论】:

      猜你喜欢
      • 2021-03-16
      • 2021-03-17
      • 1970-01-01
      • 2020-09-13
      • 2019-10-20
      • 2022-01-19
      • 2014-05-11
      • 2021-04-17
      • 1970-01-01
      相关资源
      最近更新 更多