Python 属性错误:';消息';对象没有属性';消息';
我正在创建一个系统,当聊天时自动建立EXP,当某些EXP被填满时自动升级 当使用Python 属性错误:';消息';对象没有属性';消息';,python,discord,discord.py,Python,Discord,Discord.py,我正在创建一个系统,当聊天时自动建立EXP,当某些EXP被填满时自动升级 当使用@bot.command()时,它工作得很好,但我必须输入level才能使其工作,当您切换到@bot.event并随时聊天时,会出现以下错误: @bot.command() async def level(ctx) : file = openpyxl.load_workbook("level.xlsx") sheet = file.active exp = [10, 2
@bot.command()
时,它工作得很好,但我必须输入level才能使其工作,当您切换到@bot.event
并随时聊天时,会出现以下错误:
@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
如何修复错误?查看代码和错误片段,我认为您需要将
ctx.message.author.id
替换为ctx.author.id
。
我可能又错了,因为您没有提供完整的错误堆栈跟踪현재레벨 => 现在,如果修改代码,将出现以下错误。AttributeError:“Message”对象没有属性“send”替换
Message。将发送到Message.channel。发送有关详细信息,请参阅错误已解决!谢谢你的回复。
AttributeError: 'Message' object has no attribute 'message'