首页 > 解决方案 > 有什么方法可以通过 url 向 DISCORD 发送消息?

问题描述

使用电报,可以仅使用裸 url 将消息发送到频道:

https://api.telegram.org/bot[BOT_API_KEY]/sendMessage?chat_id=[MY_CHANNEL_NAME]&text=[MY_MESSAGE_TEXT]

Discord 有什么可能吗?那么,使用纯 URL (get) 请求发送消息?

标签: discord

解决方案


如果您想以机器人的身份向通道发送消息,您将向端点发送一条 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

推荐阅读