discord.py - AttributeError:“str”对象没有属性“channel”
问题描述
AttributeError: 'str' object has no attribute 'channel' 是我得到的错误。然而,我一直在环顾四周,答案仍然不清楚。该代码以前可以工作,但现在不行。我认为我没有对频道属性进行任何更改。
client = discord.Client()
@client.event
async def on_message(message):
if 'SJAY' in u:
message = '{0.author.mention}, Did you know Sjay is a God?'.format(message)
await client.send_message(message.channel, message)
client.loop.create_task(change_stat())
client.run(TOKEN)
解决方案
那是因为在使用它之前,您将其值更改为字符串。进行以下更改将解决该问题:
client = discord.Client()
@client.event
async def on_message(message):
if 'SJAY' in u:
msg = '{0.author.mention}, Did you know Sjay is a God?'.format(message)
await client.send_message(message.channel, msg)
client.loop.create_task(change_stat())
client.run(TOKEN)
推荐阅读
- c++ - 为什么 [class.temporary]/2 中的注释 3?第 (2.1) 至 (2.6) 段不应该具有规范地位吗?
- flutter - 在颤振中,如何在异步函数执行完成后严格触发某些事情?
- python - 为什么不是所有标签都显示在 matplotlib 图例中?
- python - Selenium Automation 将文件保存到目录
- visual-studio-code - 为什么我在 VS Code 中出现终端错误?
- excel - 如何抑制更改事件以允许在 vlookup 期间使用全部值?
- python-3.x - 如何使用整数键制作 TypedDict?
- c# - 防止将特定异常记录到 App Insights
- python - TypeError: unhashable type: 'LineString' 当使用 ox.simplify_graph()
- python - 有没有办法限制客户端在 Python 聊天室应用程序中发送的消息数/秒?