'Missing argument is required | Discord.py

I tried to make an command which displays mentioned users avatar.

This is the code:

@client.command(aliases=['av'])
async def avatar(ctx, *, member: discord.Member):
    if member == None:
        member = ctx.author

    await ctx.channel.purge(limit=1)
    em = discord.Embed(title=f"{member}'s Avatar", color=member.color)
    em.set_image(url=member.avatar_url)
    await ctx.send(embed=em)

And it gives off this error:

Ignoring exception in command avatar:
Traceback (most recent call last):
  File "C:\Users\pc\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\pc\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 855, in invoke
    await self.prepare(ctx)
  File "C:\Users\pc\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 789, in prepare
    await self._parse_arguments(ctx)
  File "C:\Users\pc\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 706, in _parse_arguments
    kwargs[name] = await self.transform(ctx, param)
  File "C:\Users\pc\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 542, in transform
    raise MissingRequiredArgument(param)
discord.ext.commands.errors.MissingRequiredArgument: member is a required argument that is missing.


Solution 1:[1]

If you are using if member == None:, you're supposed to add member : discord.Member=None as well.

So your code would be:

@client.command
async def avatar(ctx, *, member: discord.Member=None):
    if member == None:
        member = ctx.author

    await ctx.channel.purge(limit=1)
    em = discord.Embed(title=f"{member}'s Avatar", color=member.color)
    em.set_image(url=member.avatar_url)
    await ctx.send(embed=em)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lil_Revive