Python 密钥权限
我希望在roleinfo中它应该显示关键权限,但我不知道怎么做。请帮帮我Python 密钥权限,python,discord,discord.py,Python,Discord,Discord.py,我希望在roleinfo中它应该显示关键权限,但我不知道怎么做。请帮帮我 @client.command() async def roleinfo(ctx, role: discord.Role): if ctx.author.guild_permissions.administrator: dd = ctx.guild.roles if role in dd: embed = discord
@client.command()
async def roleinfo(ctx, role: discord.Role):
if ctx.author.guild_permissions.administrator:
dd = ctx.guild.roles
if role in dd:
embed = discord.Embed(title="Role information", colour=discord.Color.gold(), timestamp=datetime.utcnow())
fields = [("Name", str(role), False),
("ID", role.id, False),
("Color", role.color, False),
("Mentionable", role.mentionable, False),
("Position", role.position, False),
("Created at", role.created_at.strftime("%d/%m/%Y %H:%M:%S"), False),
("Key Permissions ", role.permissions, False)]
for name, value, inline in fields:
embed.add_field(name=name, value=value, inline=inline)
await ctx.send(embed=embed)
else:
await ctx.send("Not enough permissions")
我希望我能正确地理解你。您可以获取所有角色权限的True或False标志。一个简单的例子:
@bot.command(pass\u context=True)
异步def roleinfo(ctx,角色:discord.role):
嵌入=discord.embed(title=“角色信息”,
color=discord.color.gold())
#权限命令
true_permissions=dict()
false_permissions=dict()
#获取所有权限的标志
对于键,role.permissions中的值:
如果值:
true\u权限[键]=值
其他:
false\u权限[键]=值
字段=[(“真密钥权限”,真权限,假),
(“假密钥权限”,假权限,假)]
对于名称、值、内联字段:
embed.add_字段(name=name,value=value,inline=inline)
等待ctx.channel.send(嵌入=嵌入)
结果:
或者,如果要获取权限值:role.permissions.value
。文件:
值
原始值。此值是53位整数的位数组字段,表示当前可用的权限。您应该通过属性查询权限,而不是使用此原始值
我不确定这是你想要的,但是试试看 你可以找到更多
是的,这正是我想要的,但我只是想展示一下经理的权限。我想你可以通过创建一个列表来展示你想在embed中显示的权限。并检查权限是否在您创建的列表中,然后显示它
@bot.command()
async def roleinfo(ctx, role: discord.Role):
if ctx.author.guild_permissions.administrator:
dd = ctx.guild.roles
if role in dd:
embed = discord.Embed(title="Role information", colour=discord.Color.gold(), timestamp=datetime.utcnow())
perms_string = ""
for perm, true_false in role.permissions:
if true_false is True:
perms_string += f"{perm}, "
fields = [("Name", str(role), False),
("ID", role.id, False),
("Color", role.color, False),
("Mentionable", role.mentionable, False),
("Position", role.position, False),
("Created at", role.created_at.strftime("%d/%m/%Y %H:%M:%S"), False),
("Key Permissions ", perms_string, False)]
for name, value, inline in fields:
embed.add_field(name=name, value=value, inline=inline)
await ctx.send(embed=embed)
else:
await ctx.send("Not enough permissions")