Converting to “discord.member” failed for parameter “member”

@bot.command()
async def test(ctx,user : discord.member):
    if user==None:
        user=ctx.author
    
    test=Image.open("test.jpg")

    asset=ctx.author.avatar_url_as(size=128)
    data = BytesIO(await asset.read())
    pfp=Image.open(data)
    pfp=pfp.resize((177,177))
    test.paste(pfp,(446,339))


    test.save("test1.jpg")
    await ctx.send(file=discord.file('test1.jpg'))

its not working and i am getting following errors

if i type !test it would show me this error discord.ext.commands.errors.MissingRequiredArgument: user is a required argument that is missing.

but if use !test @mention.some.username it will show me this error Converting to “discord.member” failed for parameter “user”.

Answer

There are two mistakes that you are doing here.

  • discord.member is a module, You are meant to use discord.Member class for annotation of user.
  • You are doing:
    if user == None:
      user = ctx.author
    
    but you haven’t set a default value to user so it is a required argument.

The correct way is:

@bot.command()
async def test(ctx, user: discord.Member = None):
  if user is None:
    user = ctx.author

  # rest of code here

We just declared a default value to the user as None and properly annotate user as discord.Member