python - 使用 discord.py 使用 Python 向 Discord 发送消息
问题描述
我正在创建一个监控在线内容的机器人,我已经完成了代码并在终端中运行。我想使用 discord.py 在 Discord 的频道中打印我的结果,而无需来自 Discord 用户的命令/输入。我只希望我的程序在在线获取产品时向我在 Discord 中的服务器发送一条消息。我怎样才能做到这一点?
解决方案
您必须从 id 获取频道,然后使用send
.
代码(假设您的客户是client
):
channel = client.get_channel(123456789) # get channel from id
await channel.send('message here') # send message
推荐阅读
- node.js - 电子邮件 Node.js 类型错误的基础
- sql - 将 SQL 查询复制并粘贴到 MS Word
- email - 使用命令行从应用程序在浏览器中打开 GMail 帐户
- c - 在linux shell脚本中用特殊字符替换文本?
- ruby-on-rails - 相册中所有照片的 Rails 标签
- java - LinkedList .equals vs == 整数上的运算符
- c++ - C ++用户定义的函数来填充数组
- r - 关于 nls 适合 R 的问题 - 为什么这是一个奇怪的适合?
- design-patterns - Controllers should contain all the requests from a specific entity or screen?
- mysql - 如何监控mysql中特定表的SELECT语句数?