[英]How do I get a list of all the roles my discord bot has?
I am trying to get a list of all the roles my bot has from top to bottom so I can get the highest role's color.我正在尝试获取我的机器人从上到下拥有的所有角色的列表,以便获得最高角色的颜色。
you can do a loop in all roles like this using Guild.roles您可以使用Guild.roles在所有角色中执行这样的循环
@bot.command()
async def get_roles(ctx):
all_roles = []
for role in ctx.guild.roles:
all_roles.append(role.name)
all_roles.reverse()# to make it higher first
print(all_roles)
Not sure what you mean by the "highest role's color", also your post is missing your code.不确定“最高角色的颜色”是什么意思,您的帖子也缺少您的代码。
One way to get the roles the bot has in the guild (via a command) is to get the guild member object and then loop the role objects for that member.获取机器人在公会中的角色的一种方法(通过命令)是获取公会成员对象,然后循环该成员的角色对象。
Try this:尝试这个:
@bot.command()
async def list_roles(ctx):
bot_member = ctx.guild.get_member(bot.user.id)
for bot_role in bot_member.roles:
print(f'guild role {bot_role} color {bot_role.color}')
Console output:控制台输出:
guild role @everyone color #000000
guild role masterbot color #2ecc71
guild role winnerPicker color #e67e22
guild role gabAdmin color #ad1457
you can do with .me
in a guild你可以在公会中使用.me
Guild = THE GUILD YOU WANT TO GET THE ROLES
BotMember = GUILD.members.me
for role in BotMember.roles:
print(f'Role: {role.name} Color: {role.color}')
console log:控制台日志:
Role: @everyone Color: #000000
Role: BaldeGuy Color: #2ecc71
Role: Lorrita Color: #e67e22
Role: Moderator Color: #ad1457
Guild = THE GUILD YOU WANT TO GET THE ROLES
BotMember = GUILD.members.me
HighestRole = BotMember.roles.highest.name
print(f'Highest role: {HighestRole}')
console.log:控制台日志:
Highest role: {Moderator}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.