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