I'm trying to do a info command as you can see but in the roles section, i can't display the user's roles.
At first i did a working command but it display the "@everyone" role too, so i did a string for remove it (mention.remove("everyone")
) but it doesn't work it gives an this error:
Command raised an exception: ValueError: list.remove(x): x not in list
我也尝试用“ @everyone”替换“ everyone”,但仍然无法正常工作。
@client.command()
async def info(ctx, user: discord.Member):
mention = []
for role in user.roles:
mention.append(role.mention)
mention.remove("everyone")
b = ", ".join(mention)
embed = discord.Embed(title="Info:", description=f"Info of: {user.mention}", color=discord.Color.orange())
embed.add_field(name="Top role:", value=user.top_role)
embed.add_field(name="Roles:", value=b)
await ctx.send(embed=embed)
You should simply use
if
to check value before you add to list - and then you don't needremove
与列表理解相同
BTW: if you want to remove something then do it only once after
for
-loop and also useif
to check if element exists