python - discord.ext.commands.errors.CommandInvokeError:命令引发异常:AttributeError:'Command'对象没有属性'strftime'
问题描述
我试图制作一个机器人命令,您可以在其中询问机器人是否是星期三,但我不断收到此错误,我不知道该怎么做。请帮忙。这是我的代码:
@client.command(aliases=['wednesdaymydudes', 'wednesday', 'wednesdaycheck'],
pass_context=True)
async def isitwednesdaymydudes(ctx):
currentday = time.strftime('%A')
if currentday == 'Wednesday':
await ctx.send('It is Wednesday, {}'.format(ctx.message.author.mention))
else:
await ctx.send('It is not Wednesday, {}'.format(ctx.message.author.mention))
解决方案
为了获得星期几,你应该做的是
from datetime import datetime as dt
day = dt.now()
day_of_week = day.strftime('%A')
推荐阅读
- javascript - 有没有办法剥离原型方法并使其作为函数工作?
- mysql - 有效日期的 MySQL 不正确的日期时间值错误
- angular - 以理智的方式在 NGXS 中声明状态
- pandas - 如何使用 seaborn 显示多个时间序列图
- ruby-on-rails - 如何配置 docker 以使用 byebug?
- javascript - TestCafe runner.video 不是 createTestCafe.then.then.remoteConnection 中的函数
- javascript - 应用 sum 函数将列的总和从 csv 解析为 d3.js-chart
- powerbi - 无法注册/登录 Power BI 社区
- c# - 为什么我不能使用 Global.asax.cs 中 Models 文件夹中的类?
- json - 无法将外部结构直接调用到 map[string]struct