discord - 有什么方法可以通过 url 向 DISCORD 发送消息?
问题描述
使用电报,可以仅使用裸 url 将消息发送到频道:
https://api.telegram.org/bot[BOT_API_KEY]/sendMessage?chat_id=[MY_CHANNEL_NAME]&text=[MY_MESSAGE_TEXT]
Discord 有什么可能吗?那么,使用纯 URL (get) 请求发送消息?
解决方案
如果您想以机器人的身份向通道发送消息,您将向端点发送一条 POST 消息,/channels/{channel.id}/messages
但还需要验证/识别自己,首先:
在使用此端点之前,您必须至少连接到网关并识别一次网关。
但是,您可以执行类似的操作:使用 Webhook 设置和发送消息,该 Webhook在请求之前不需要身份验证过程。
Integrations
您可以在>下的频道设置中为频道设置 webhook WebHooks
。您可以在此处单击Copy Webhook URL
以复制 URL。
URL 将如下所示:https://discord.com/api/webhooks/<Webhook ID>/<Webhook token>
。
然后,您可以使用消息负载向 webhook url 发送 POST 请求。
它可以是具有以下字段的 JSON/Form 有效负载(从docs复制):
FIELD TYPE DESCRIPTION REQUIRED
content string the message contents (up to 2000 characters) one of content, file, embeds
username string override the default username of the webhook false
avatar_url string override the default avatar of the webhook false
tts boolean true if this is a TTS message false
file file contents the contents of the file being sent one of content, file, embeds
embeds array of up to 10 embed objects embedded rich content one of content, file, embeds
payload_json string See message create multipart/form-data only
allowed_mentions allowed mention object allowed mentions for the message false
推荐阅读
- javascript - Javascript,Geojson,Json
- java - 如何构建使用 java11 的 docker 镜像
- stargazer - 找不到函数“multinom”nnet 错误 + stargazer 问题
- scala - 如何使用模式字段选择数据框列
- python - FileNotFoundError: [Errno 2] 没有这样的文件或目录 (Python)
- pandas-groupby - 在 Dask 数据帧上分组,然后按一列排序
- app-engine-flexible - 有没有办法在 GCP AppEngine 上阻止 HTTP
- ruby-on-rails - Rails 6 Heroku 设计错误 ActiveSupport::MessageEncryptor::InvalidMessage
- html - 我使用 col 属性添加了两个相邻的视频,但在小屏幕中,它被堆叠而没有间距
- python - 选择自动填写表格