首页 > 解决方案 > 使用 discord.py 使用 Python 向 Discord 发送消息

问题描述

我正在创建一个监控在线内容的机器人,我已经完成了代码并在终端中运行。我想使用 discord.py 在 Discord 的频道中打印我的结果,而无需来自 Discord 用户的命令/输入。我只希望我的程序在在线获取产品时向我在 Discord 中的服务器发送一条消息。我怎样才能做到这一点?

标签: pythondiscorddiscord.py

解决方案


您必须从 id 获取频道,然后使用send.

代码(假设您的客户是client):

channel = client.get_channel(123456789) # get channel from id
await channel.send('message here') # send message

推荐阅读