Python开发Discord Bot报错:'Message'对象无'channell'属性的解决
问题原因与修复方案
问题原因
终端报错'Message' object has no attribute 'channell'是因为拼写错误:在bot.py的send_message函数里,你把Discord Message对象的channel属性写成了channell(多了一个字母l)。这个错误导致机器人尝试调用不存在的属性,无法发送响应消息,所以用户输入"hello"时看不到机器人回复。
修复方法
修改bot.py中send_message函数的错误代码行:
错误代码:
await message.author.send(response) if is_private else await message.channell.send(response)
修正后的代码:
await message.author.send(response) if is_private else await message.channel.send(response)
仅需把channell改为channel,机器人就能正确定位消息所在频道并发送响应。
内容的提问来源于stack exchange,提问作者Loh Boon How
相关产品推荐
相关产品推荐

