AttributeError。 。:'NoneType'对象没有属性'send'

时间:2020-11-04 20:44:33

标签: python discord discord.py attributeerror discord.py-rewrite

我的代码:

@commands.Cog.listener()
async def on_command(self, ctx):
    channel = client.get_channel(int(772906069885321236))
    await channel.send(discord.Object(id=772906069885321236), f"{ctx.guild.name} {ctx.author} {ctx.message.clean_content}")

我尝试使用意图,但我似乎也无法弄清楚它们

2 个答案:

答案 0 :(得分:0)

根据docs,如果找不到指定的频道,get_channel返回None

答案 1 :(得分:0)

如果找不到频道,

get_channel返回None。您可以添加一些错误处理来解决此问题 if 对您正在构建的项目有意义。

@commands.Cog.listener()
async def on_command(self, ctx):
    try:
        channel = client.get_channel(int(772906069885321236))
        await channel.send(discord.Object(id=772906069885321236),
                     f"{ctx.guild.name} {ctx.author} {ctx.message.clean_content}")
    except:
        print("Channel not found")