首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AttributeError:“message”对象没有属性“message”

AttributeError:“message”对象没有属性“message”
EN

Stack Overflow用户
提问于 2020-08-25 22:35:22
回答 1查看 2.9K关注 0票数 2
代码语言:javascript
复制
@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

我正在创建一个系统,当任何聊天时,自动建立exps,并在某些exps被填满时升级。

在使用@bot.command()时,它工作得很好,但我必须输入level才能使它工作,当您随时切换到@bot.event并聊天时,会出现以下错误:

代码语言:javascript
复制
AttributeError: 'Message' object has no attribute 'message'

我如何修复这个错误?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-25 22:48:01

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63581226

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档