python - 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")
推荐阅读
- javascript - 第一个页面加载后未触发 ajax__fileupload_selectFileContainer
- c# - 获取重复的 Arraylist(s),针对 Arraylist 中的每个索引放置
- ios - UIWebView 内容加载成功但弹出
- bash - 尝试更改目录时出现“太多参数”
- bash - 如何从字符串中删除字符
- jquery - 如果容器具有特定元素,则更改容器的宽度
- c++ - 在 ofstream 写入期间检测到空间不足,stream.fail() 无法工作
- c# - 从结构类型获取静态属性
- javascript - 如何像 cricbuzz 网站一样在分页中创建标签?
- reactjs - 将映射数据传递给 Material-UI 模态