Discord.py:我如何获得bot角色并更改其颜色?



所以我想让我的机器人扮演他自己的角色并编辑它来改变颜色,但是我没有找到任何东西。我试着在on_ready下用discord.utils.get得到它,但它不起作用。你们能帮帮我吗?

除非用户是公会(服务器)的所有者,否则他们不能编辑自己的顶级角色。因此,这有点难以实现。你要做的是获取机器人的第二个角色,然后编辑该角色的颜色。

@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

要使其工作,bot必须至少有2个角色。顶部角色应该设置为默认的(不可见的)颜色,所以编辑底部角色的颜色将编辑机器人显示的颜色角色的颜色。

最新更新