python 嵌入中的新用户名

wh6knrhe  于 2023-06-20  发布在  Python
关注(0)|答案(1)|浏览(93)

所以,我有我的机器人,我有一个/info用户命令,得到一些用户信息。如果用户有新用户名,我想做一个“如果”。我在/dm命令中这样做了,但它在/info用户命令上不起作用。下面是我的代码:

@info.command(name="user", description="Mostra informações sobre um usuário")
async def _info(self, interaction: discord.Interaction, member: discord.Member):
    await interaction.response.defer()
    if member.discriminator.endswith("0"):
        membro = member.discriminator.strip("#0")
        member = membro
          
    info_embed = discord.Embed(color=discord.Color.green())
    info_embed.set_thumbnail(url=f"{member.display_avatar})")
    info_embed.add_field(name=":placard: Nome", value=f"```{member}```", inline=True)
    info_embed.add_field(name=":identification_card: Identidade", value=f"```{member.id}```", inline=True)
    info_embed.add_field(name=":link: Menção", value=f"{member.mention}", inline=True)
    created = member.created_at.timestamp()
    info_embed.add_field(name=":calendar_spiral: Conta Criada", value=f'<t:{int(created)}:F> (<t:{int(created)}:R>)', inline=True)
    joined = member.joined_at.timestamp()
    info_embed.add_field(name=":date: Entrou em", value=f'<t:{int(joined)}:F> (<t:{int(joined)}:R>)', inline=False)
    
    await interaction.followup.send(embed=info_embed)

有一个错误:discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: AttributeError: 'NoneType' object has no attribute 'discriminator'
顺便说一下,“info”是一个斜杠命令组。

sr4lhrrt

sr4lhrrt1#

我修好了

@info.command()
async def _info(self, interaction, member: discord.Member):
    await interaction.response.defer()
    if member.discriminator == "0":
        membro = member.name
    else:
        membro = member
    
    info_embed = discord.Embed(color=discord.Color.blurple())
    info_embed.add_field(name=":placard: Nome", value=f"```{membro}```", inline=True)
...

相关问题