@commands.command()
async def info(self, ctx, member: discord.Member = None):
if member is None:
member = ctx.author
name = str(member.name)
avatar = str(member.avatar_url)
bot = str(member.bot)
created = str(member.created_at)
joined = str(member.joined_at)
id = str(member.id)
roles = member.roles
emb = discord.Embed(
title="Member Information",
color=discord.Color.blue()
)
emb.set_thumbnail(url=avatar)
emb.add_field(name="Member", value=name, inline=True)
emb.add_field(name="User ID", value=id, inline=True)
emb.add_field(name="Created On", value=created, inline=False)
emb.add_field(name="Joined At", value=joined, inline=True)
emb.add_field(name="Bot", value=bot, inline=False)
emb.add_field(name="Roles", value=roles, inline=True)
await ctx.send(embed=emb)
else:
name = str(member.name)
avatar = str(member.avatar_url)
bot = str(member.bot)
created = str(member.created_at)
joined = str(member.joined_at)
id = str(member.id)
roles = member.roles
embed = discord.Embed(
title="Member Information",
color=discord.Color.blue()
)
embed.set_thumbnail(url=avatar)
embed.add_field(name="Member", value=name, inline=True)
embed.add_field(name="User ID", value=id, inline=True)
embed.add_field(name="Created On", value=created, inline=False)
embed.add_field(name="Joined At", value=joined, inline=True)
embed.add_field(name="Bot", value=bot, inline=False)
embed.add_field(name="Roles", value=roles, inline=True)
await ctx.send(embed=embed)
这是我的命令,我想不出让机器人提及命令的角色而不是所有这些的方法:
[<Role id=794621342585847829 name='@everyone'>, <Role id=794728482365898752 name='Members'>, <Role id=801106344777351179 name='Alpha Testers'>, <Role id=794624055969054741 name='Server Dev'>, <Role id=809075308808372234 name='Dev Team'>, <Role id=794623964436627466 name='Bot Dev'>]
我认为这就是当您拥有 member.roles
时机器人发送的内容,但我不知道如何更改它,我尝试过 members.roles.mention
,但它只是发送一条错误消息。
答案 0 :(得分:1)
member.roles
将始终给出一个角色列表,其中还包含 @everyone
角色,所有角色均按角色层次结构中的位置排序。您可以查看docs。
试试这个:
roles1 = [role.mention for role in user.roles if role != ctx.guild.default_role]
emb.add_field(name=f"Roles ({len(roles1)}):", value=', '.join(roles1), inline=False)
这将提及角色并用 ,
分隔它们。它还排除了 @everyone
角色。
如果您想删除计数器,只需删除 {len(roles1)}
。
这是一个可能的输出: