首页 > 解决方案 > 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)

标签: discord.py

解决方案


那是因为在使用它之前,您将其值更改为字符串。进行以下更改将解决该问题:

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)

推荐阅读