TypeError: descriptor 'strftime' for 'datetime.date' objects doesn't apply to a 'NoneType' object

Viewed 862

This is my code for this command:

@client.command()
async def nitrosince(ctx, member: discord.Member, guild: discord.Guild = None):
  member = ctx.member if not member  else member
  guild = ctx.guild if not guild else guild

  embed = discord.Embed(
        colour=discord.Colour.blue(),
        title="NitroSince Command",
        
    )

  embed.add_field(name=f"{member} Has had Nitro Since:", value = datetime.date.strftime(member.premium_since, '%a, %b %d %Y')

)
  embed.set_footer(text="I was made by Grenade Visuals#0001", icon_url=ctx.author.avatar_url)
  await ctx.send(embed=embed)

And whenever I run this code I get the error "discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: descriptor 'strftime' for 'datetime.date' objects doesn't apply to a 'NoneType' object" Does anyone know why this is? And how I could possibly fix this?!

1 Answers

This error means that member.premium_since is None, which is not a valid date.

You'll need to add code to support cases when that value is None, i.e. when someone is not premium.

Related