Python 如何使用discord.py自动发送消息?

Python 如何使用discord.py自动发送消息?,python,discord.py,Python,Discord.py,错误: import discord,random,asyncio from discord.ext import commands client = commands.Bot(command_prefix = '/') async def auto_send(): await send_msg('GOOD MORNING!') await asyncio.sleep(28800) async def send_msg(msg): channel = a

错误:

import discord,random,asyncio
from discord.ext import commands
client = commands.Bot(command_prefix = '/')

async def auto_send():
    await send_msg('GOOD MORNING!')       
    await asyncio.sleep(28800)

async def send_msg(msg):
    channel = await client.fetch_channel('channel_id')
    await channel.send(msg)

client.loop.create_task(auto_send())
client.run(token)
从未检索到任务异常 未来: 回溯(最近一次呼叫最后一次): 文件“C:\Users\StudMuffin\Desktop\Things\Discord Bots\Youtube Channel YT\Youtube\u get.py”,第41行,自动发送 等待发送消息(“早上好!”) 文件“C:\Users\StudMuffin\Desktop\Things\Discord Bots\Youtube Channel YT\Youtube\u get.py”,第50行,在send\u msg中 通道=等待客户端。获取通道(通道id) 文件“C:\Users\StudMuffin\AppData\Local\Programs\Python\Python38-32\lib\site packages\discord\client.py”,第1457行,在fetch\u通道中 data=wait self.http.get_通道(通道id) 请求中第185行的文件“C:\Users\StudMuffin\AppData\Local\Programs\Python38-32\lib\site packages\discord\http.py” 与self.\u session.request(方法、url、**kwargs)异步,作为r: AttributeError:“非类型”对象没有属性“请求”
我不理解这个错误。我在想,也许通过某种方式循环信息,它正在做一些我没有意识到的事情,因此它没有按照我的意愿工作。还是我循环这个异步函数的方式?

我认为错误是由于协同程序没有被所需的discord.py装饰器装饰

但是,您可能需要在这种情况下进行调查

@tasks.loop(小时=8.0)
异步def自动发送():
通道=等待客户端。获取通道(“通道id”)
等待频道。发送(“早上好!”)

频道id在哪里定义?我确实定义了它,只是没有显示它不起作用,我忘记在事件中添加auto\u send.start(),准备启动循环,忘记导入任务。最后一切都解决了:)
Task exception was never retrieved
future: <Task finished name='Task-2' coro=<auto_send() done, defined at C:\Users\StudMuffin\Desktop\Things\Discord Bots\Youtube Channel YT\Youtube_get.py:31> exception=AttributeError("'NoneType' object has no attribute 'request'")>
Traceback (most recent call last):
  File "C:\Users\StudMuffin\Desktop\Things\Discord Bots\Youtube Channel YT\Youtube_get.py", line 41, in auto_send
    await send_msg('GOOD MORNING!')
  File "C:\Users\StudMuffin\Desktop\Things\Discord Bots\Youtube Channel YT\Youtube_get.py", line 50, in send_msg
    channel = await client.fetch_channel(channel_id)
  File "C:\Users\StudMuffin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 1457, in fetch_channel
    data = await self.http.get_channel(channel_id)
  File "C:\Users\StudMuffin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\http.py", line 185, in request
    async with self.__session.request(method, url, **kwargs) as r:
AttributeError: 'NoneType' object has no attribute 'request'