【问题标题】:Discord.py: How can I get the bot role and change his color?Discord.py:我怎样才能获得机器人角色并改变他的颜色?
【发布时间】:2021-06-03 08:29:41
【问题描述】:

所以我希望我的机器人扮演自己的角色并对其进行编辑以更改颜色,但我没有找到任何东西。 我试图在on_ready 下使用discord.utils.get 来获取它,但它不起作用。 你们能帮帮我吗?

【问题讨论】:

  • 机器人无法编辑自己的角色,无论你做什么都是不可能的

标签: python discord discord.py bots roles


【解决方案1】:

除非用户是公会(服务器)的所有者,否则他们无法编辑其最高角色。因此,这有点难以实现。您要做的是获取机器人的倒数第二个角色,然后编辑该角色的颜色。

@bot.command()
async def color(ctx):
    bot_member = ctx.guild.get_member(bot.user.id)
    if len(bot_member.roles) < 3:  # bot needs 3 roles, @everyone, the bot integration role, and a role to edit
        return await ctx.send('Give me another role please!')
    else:
        role_to_edit = bot_member.roles[-2]  # the second highest role
        await role_to_edit.edit(color=discord.Color.blue())  # you can choose what you want to change this to, i used blue as an example

为此,机器人必须至少有 2 个角色。顶部角色应设置为默认(不可见)颜色,因此编辑较低角色颜色将编辑机器人显示颜色角色的颜色。

【讨论】:

    猜你喜欢
    • 2022-01-24
    • 2021-11-07
    • 2018-01-12
    • 2023-02-22
    • 2014-05-14
    • 1970-01-01
    • 2017-12-29
    • 2021-06-15
    相关资源
    最近更新 更多