【问题标题】:Discord.py can't find channel by correct channel IDDiscord.py 无法通过正确的频道 ID 找到频道
【发布时间】:2020-05-01 22:04:31
【问题描述】:

我正在尝试向我的 discord 机器人添加一项功能,以每 10 秒发送一次特定消息(消息的内容现在并不重要)。这是我的代码:

@client.event
async def on_ready():
    await client.wait_until_ready()
    await client.loop.create_task(update_task())

async def update_task():
    await client.wait_until_ready()

    chn = client.get_channel('#')
    while True:

        await chn.send('message')
        await asyncio.sleep(10)

我得到了错误:

AttributeError: 'NoneType' object has no attribute 'send'

我已经看到了几个类似的问题,所有的解决方案都是添加

await client.wait_until_ready()

之前,但这对我不起作用,我仍然得到错误。有谁知道如何解决这个问题?

【问题讨论】:

    标签: python python-3.x python-asyncio discord.py


    【解决方案1】:

    这不起作用,因为get_channel() 需要一个 int 类型的对象,该对象等于属于机器人可以访问的频道的 id。例如,这将是一个正确的用法: channel = client.get_channel(700437301263728720)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-18
      • 1970-01-01
      • 2022-01-16
      • 1970-01-01
      • 2018-12-08
      • 1970-01-01
      • 2019-02-19
      相关资源
      最近更新 更多