【发布时间】:2021-07-23 01:36:00
【问题描述】:
我为我的机器人配置和代码中的一般内容创建了一个类,我很整洁 所以,客户端是 discord.Client() 和机器人。是我的课 在我的机器人类中,我存储了一些频道 ID,然后我注意到 client.send_message(channelid, message) 方式不再支持。但是,我将频道 ID 变量编辑为
channel1=client.get_channel(channelid)
client=discord.Client() 在我的课上,它的定义。
我用它来发送消息
await bot.channel1.send("hello world")
我期待该频道中的消息,但现实:
Task exception was never retrieved
future: <Task finished name='Task-2' coro=<bot2() done, defined at /path/to/file/bot.py:46> exception=AttributeError("'NoneType' object has no attribute 'send'")>
Traceback (most recent call last):
File "/path/to/file/bot.py", line 53, in bot2
await bot.channel1.send(fc)
AttributeError: 'NoneType' object has no attribute 'send'
简而言之,我的 channel1 定义是 nonetype.. 为什么?
是的,我在我的代码中使用了另一个 async def 并运行它,因为该代码应该在 on_message() 之外运行并且应该运行 async
我在文件末尾调用了我的异步函数
client.loop.create_task(bot())
client.loop.create_task(bot2())
client.loop.create_task(dead())
client.run(bot.token)
【问题讨论】:
-
channel1已定义。bot.channel1未定义。 -
channel1 在课堂机器人
class bot: channel1=xxx -
你做了
self.channel1吗? -
嗯,我不知道这是什么意思,在哪里我必须这样做?
-
你想在哪里使用
bot.channel1?在方法内部?
标签: python discord.py