我希望我的机器人在 on_ready 事件中上线时发送一条消息。该线路在 (on_message) 中工作,但我无法让它在 (on_ready) 中发送内容
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
await message.channel.send('The bot is online ')
原文由 Sébastien 发布,翻译遵循 CC BY-SA 4.0 许可协议
您没有选择要向其发送消息的频道。首先,您需要选择一个频道,然后您可以向该频道发送消息。
您可以通过遍历已连接服务器中的频道列表来获取频道 ID:
从 How to get all text channels using discord.py?
从 如何向特定频道发送消息? 在 discord python FAQ 中。