Search code examples
discord.pybotsavatar

Hello, I'm making an avatar command. I want the embed to appear and write that the user does not have an avatar. But it doesn't work


` @commands.command(aliases=['ava', 'аватарка']) async def avatar(self, ctx, *, member: discord.Member = None): if not member: member = ctx.message.author userAvatar = member.avatar

        embed = discord.Embed(color=discord.Color.darker_grey(), timestamp=ctx.message.created_at)
        embed.set_author(name=f'Аватар {member}')
        embed.set_image(url=member.avatar)
        embed.set_footer(text=f'Выполнено {ctx.author}', icon_url=ctx.author.avatar)
        await ctx.send(embed=embed)
    if member:
        embed = discord.Embed(color=discord.Color.darker_grey(), timestamp=ctx.message.created_at)
        embed.set_author(name=f'Аватар {member}')
        embed.set_image(url=member.avatar)
        embed.set_footer(text=f'Выполнено {ctx.author}', icon_url=ctx.author.avatar)
        await ctx.send(embed=embed)`

Solution

  • I don't really understand what you need that member check for.. because everyone who can use a command is already a member on your discord or am I wrong? Maybe this will work for you?:

    @commands.command(aliases=['ava', 'аватарка'])
    async def avatar(self, ctx):
    
        author = ctx.message.author
    
        if author.avatar is None:
            await ctx.send('The author has no avatar!')
        else:
            embed = discord.Embed(color=discord.Color.darker_grey(), timestamp=ctx.message.created_at)
            embed.set_author(name=f'Аватар {author.name}')
            embed.set_image(url=author.avatar)
            embed.set_footer(text=f'Выполнено {author.name}',icon_url=ctx.author.avatar)
            await ctx.send(embed=embed)