python - 属性错误: 'Message' object has no attribute 'message'

标签 python discord discord.py

@bot.command() 
async def level(ctx) : 
    file = openpyxl.load_workbook("level.xlsx")
    sheet = file.active
    exp = [10, 20, 40, 70, 110, 160, 220, 290, 370, 460, 560]
    i = 1
    while True :
        if sheet["A" + str(i)].value == str(ctx.message.author.id) :
            sheet["B" + str(i)].value = sheet["B" + str(i)].value + 2.5
            if sheet["B" + str(i)].value >= exp[sheet["C" + str(i)].value - 1] :
                sheet["C" + str(i)].value = sheet["C" + str(i)].value + 1
                await ctx.send("Level UP !!\n현재 레벨 : " + str(sheet["C" + str(i)].value) + "\nExp : " + str(sheet["B" + str(i)].value))
            file.save("level.xlsx")
            break
        if sheet["A" + str(i)].value == None :
            sheet["A" + str(i)].value = str(ctx.message.author.id)
            sheet["B" + str(i)].value = 0
            sheet["C" + str(i)].value = 1
            file.save("level.xlsx")
            break
        i += 1

我正在创建一个系统,当进行任何聊天时,该系统会自动积累经验,并在某些经验被填充时自动升级。

当使用@bot.command()时,它运行良好,但我必须输入级别才能使其运行,当您切换到@bot.event并且任何时候聊天,都会出现以下错误:

AttributeError: 'Message' object has no attribute 'message'

如何修复该错误?

最佳答案

查看代码和错误片段,我认为您需要将 ctx.message.author.id 替换为 ctx.author.id。 同样,我可能是错的,因为您没有提供错误的完整堆栈跟踪。

关于python - 属性错误: 'Message' object has no attribute 'message' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63581226/

相关文章:

python-3.x - 如何使用 discord.py "temporary ban"某人?

python - Discord.py 如何在重写中删除单个消息

javascript - 老虎机代码尚未运行,没有错误消息?

python - Discord.py 机器人将消息重新发送到另一个 channel ,添加 react 后会中断

python - 获取公会和成员图标discord.py

xUbuntu 上的 Python 2.7.3 安装

python - 形状不可用的 OpenCV 框架

python - Django:将 gmt 时间而不是本地时间存储在数据库表中

python - Discord.py 如何删除每个文本 channel ?

python - 使用局部变量的 for 循环中的函数定义