Discord.py - 属性错误:'NoneType'对象没有属性'send'



我在随意地编程我的Discord机器人,当我完成后,我使用我的备用帐户加入测试服务器来测试我的代码(当有人加入服务器时,它会发送一条欢迎消息(。但当替代方案加入时,我得到了这个错误:

Ignoring exception in on_member_join
Traceback (most recent call last):
File "C:UsersquinnAppDataLocalProgramsPythonPython37libsite-packagesdiscordclient.py", line 343, in _run_event
await coro(*args, **kwargs)
File "E:GrindersValleyValleysPycogsHellogoodbye.py", line 36, in on_member_join
await client.get_channel(844229450928488458).send(embed=embed)
AttributeError: 'NoneType' object has no attribute 'send'

我不知道怎么了。我的代码:https://pastebin.com/VntL0y5d

首先,您的问题是clientbot的声明不一致,因此将client的所有实例更改为bot

其次,cog中对bot的所有调用都应该是self.bot,因为您在_init_中将其声明为类变量,所以例如:bot.get_channel()应为self.bot.get_channel()

第三,你的缓存可能没有填充,所以添加:

await self.bot.wait_until_ready()

以确保在尝试调用之前,客户端的缓存已完全填充

未找到

TextChannel。如果机器人无法从其缓存中获取频道,则返回None,这就是触发错误的原因。

最新更新