首页 > 解决方案 > 如何获取我的不和谐机器人拥有的所有角色的列表?

问题描述

我正在尝试获取我的机器人从上到下的所有角色的列表,以便我可以获得最高角色的颜色。

标签: pythondiscorddiscord.py

解决方案


您可以使用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)

推荐阅读