如何解决Discord客户端错误:“ NoneType”对象没有属性“发送”
启动时,它应该在一个文本通道中写一条消息。
错误:“ NoneType”对象没有属性“发送”
channel = client.get_channel(111111111) #I have the real id
message = ("Wow")
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
await client.change_presence(status=discord.Status.online,activity=game)
await channel.send(message)
解决方法
Bot
一旦准备好就可以获取频道,这意味着在漫游器尚未准备好之前您就无法获取频道。正如您所看到的,您在get_channel()
事件之前(即在机器人准备就绪之前)正在进行on_ready()
。
在on_ready
事件中获取频道,那应该很好。
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
await client.change_presence(status=discord.Status.online,activity=game) #game is not defined make sure to define it
channel = client.get_channel(channel_id)
await channel.send("Wow")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。