Discord.py如何使漫游器将消息发送到特定频道

时间:2020-10-21 20:00:16

标签: python discord discord.py

因此,我想执行一个始终保持运行状态的命令,直到发生更改为止。当发生更改时,它将向我指定的通道发送一条消息。但是,我不断收到错误消息。

import requests
from bs4 import BeautifulSoup

url = "url"
s = BeautifulSoup(requests.get(url)._content, "lxml")
canonical = s.find('link', {'rel': 'canonical'})
result = canonical['href']

    async def test():
      if result == url:
        channel = bot.get_channel(766572517367873556)
        await channel.send("checking.....\n"+ url + "\n(1) result Found")
        await asyncio.sleep(10)


bot.loop.create_task(test())

这是错误:

File "C:path\bot.py", line 91, in patch
    await channel.send("checking.....\n"+ url + "\n(1) result Found")
AttributeError: 'NoneType' object has no attribute 'send'

任何帮助将不胜感激:)

1 个答案:

答案 0 :(得分:1)

您正在尝试在漫游器就绪之前使用该频道。尝试在channel = bot.get_channel(766572517367873556)行之前添加以下行。

await bot.wait_until_ready()

放在一边-请仔细检查您的缩进。