Discord.py: 如何获得机器人角色并改变他的颜色?
Discord.py: How can I get the bot role and change his color?
所以我想让我的机器人扮演他自己的角色并编辑它来改变颜色,但我没有找到任何东西。
我试图在 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
要使其正常工作,机器人必须至少有 2 个角色。顶部角色应设置为默认(不可见)颜色,因此编辑较低角色颜色将编辑机器人显示颜色角色的颜色。
所以我想让我的机器人扮演他自己的角色并编辑它来改变颜色,但我没有找到任何东西。
我试图在 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
要使其正常工作,机器人必须至少有 2 个角色。顶部角色应设置为默认(不可见)颜色,因此编辑较低角色颜色将编辑机器人显示颜色角色的颜色。