【问题标题】:TypeError: descriptor 'strftime' for 'datetime.date' objects doesn't apply to a 'NoneType' objectTypeError:“datetime.date”对象的描述符“strftime”不适用于“NoneType”对象
【发布时间】:2020-11-01 20:00:07
【问题描述】:

这是我的这个命令的代码:

@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)

每当我运行此代码时,我都会收到错误“discord.ext.commands.errors.CommandInvokeError:命令引发异常:TypeError:'datetime.date'对象的描述符'strftime'不适用于'NoneType '对象“有谁知道这是为什么?我怎么可能解决这个问题?!

【问题讨论】:

  • 这意味着你尝试做datetime.date.strftime( None, ...),这意味着你在member.premium_since中有None。所以使用print( member.premium_since ) 来检查你有什么。您可以使用if/else 跳过它或发送不同的消息。

标签: python python-3.x visual-studio-code discord.py


【解决方案1】:

这个错误意味着member.premium_sinceNone,这不是一个有效的日期。

当该值为None 时,您需要添加代码来支持案例,即当某人不是高级时。

【讨论】:

    猜你喜欢
    • 2021-10-26
    • 2022-01-21
    • 1970-01-01
    • 2021-09-14
    • 2020-03-18
    • 2022-11-26
    • 1970-01-01
    • 2020-06-30
    • 2021-07-01
    相关资源
    最近更新 更多