【问题标题】:discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Command' object has no attribute 'strftime'discord.ext.commands.errors.CommandInvokeError:命令引发异常:AttributeError:'Command'对象没有属性'strftime'
【发布时间】:2020-06-11 15:50:42
【问题描述】:

我正在尝试创建一个机器人命令,您可以在其中询问机器人是否是星期三,但我不断收到此错误,我不知道该怎么做。请帮忙。 这是我的代码:

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

【问题讨论】:

  • 你有另一个函数名为time的命令吗?看起来有其他东西以该名称隐藏了 Python 模块(或者您尚未导入它)。

标签: python discord.py discord.py-rewrite


【解决方案1】:

为了得到星期几,你应该做的是

from datetime import datetime as dt

day = dt.now()

day_of_week = day.strftime('%A')

【讨论】:

    猜你喜欢
    • 2021-01-30
    • 2021-12-07
    • 2022-01-25
    • 1970-01-01
    • 2022-01-05
    • 2021-02-05
    • 1970-01-01
    • 2021-12-04
    • 2021-07-18
    相关资源
    最近更新 更多