我发出了这样的命令,但我不希望该机器人说每个人都扮演角色,我想看看权限键可以帮助我吗?
@client.command()
async def userinfo(ctx, target: Optional[Member]):
if ctx.author.guild_permissions.administrator:
x = ctx.guild.members
if target in x:
roles = [role for role in target.roles]
embed = discord.Embed(title="User information", colour=discord.Color.gold(), timestamp=datetime.utcnow())
embed.set_author(name=target.name, icon_url=target.avatar_url)
embed.set_thumbnail(url=target.avatar_url)
embed.set_footer(text="Mr.KapiBara", icon_url="https://cdn.discordapp.com/attachments/618434755981213716/718861010223497236/kapi-1.png")
fields = [("Name", str(target), False),
("ID", target.id, False),
("Status", str(target.status).title(), False),
(f"Roles ({len(roles)})", " ".join([role.mention for role in roles]), False),
("Created at", target.created_at.strftime("%d/%m/%Y %H:%M:%S"), False),
("Joined at", target.joined_at.strftime("%d/%m/%Y %H:%M:%S"), 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(f'You have to ping soneone from this server')
else:
await ctx.send(f'Not enough permissions')
答案 0 :(得分:0)
roles = [role for role in target.roles]
这种理解正在发挥所有作用。
您可以使用条件允许除@everyone
(默认角色)之外的所有角色:
roles = [role for role in target.roles if role != ctx.guild.default_role]
参考: