【问题标题】:AttributeError . .: 'NoneType' object has no attribute 'send'属性错误。 .: 'NoneType' 对象没有属性 'send'
【发布时间】:2021-02-17 14:02:05
【问题描述】:

我的代码:

@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}")

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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      如果找不到频道,get_channel 返回None。您可以添加一些错误处理来解决此问题如果,这对您正在构建的项目有意义。

      @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")
      

      【讨论】:

        猜你喜欢
        • 2021-07-27
        • 1970-01-01
        • 1970-01-01
        • 2023-01-23
        • 2017-09-14
        • 2023-02-17
        • 2018-05-02
        • 2019-03-17
        • 1970-01-01
        相关资源
        最近更新 更多