使用Discord API在给定用户ID的情况下发送私人消息 [英] Use Discord API to send a private message given a user ID

查看:44
本文介绍了使用Discord API在给定用户ID的情况下发送私人消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用 Discord的API 向用户发送新的私人消息,并为其指定用户ID.

I have been attempting to use Discord's API to send a new private message to a user, given their user ID.

我知道使用Discord.JS和Discord.py之类的库是可行的-请不要推荐我使用那些库,我很清楚自己想做的事情.我曾尝试查看Discord.js之类的库的源,但似乎找不到与特定用户一起创建新DM所需的端点.

I am aware this is possible using libraries such as Discord.JS and Discord.py - please do not recommend me to use those, I am quite aware of what I am wanting to do. I've tried looking at the source for libraries like Discord.js but can't seem to find the endpoint needed to create a new DM with the specific user.

此外,Discord的文档在该主题上不清楚,在线研究也很广泛.

In addition, Discord's documentation are unclear on the topic and research online is broad.

这是我当前的代码(由于端点不正确,因此显然无法正常工作):

Here is my current code(which obviously won't work as the endpoint isn't correct):

const discordToken = "some-token";
const discordID = "some-user-id";
const userURL = `https://discordapp.com/api/users/${discordID}`;
    fetch(userURL, {
        method: 'POST',
        body: JSON.stringify({
            recipent_id: discordID,
            embed: {
              title: `Testing - Title `,
              description: `Testing - Description`
            }
        }), 
        headers: {
            'Content-Type': 'application/json',
            'Authorization': 'Bot ' + discordToken
          },
    })

如果有人知道正确的终结点或实现此目标的其他方法(使用纯POST请求,没有外部库),请告诉我,谢谢.

If anyone knows the proper endpoint or another way to achieve this(using purely POST requests, no external libraries), please let me know, thanks.

推荐答案

请注意,我没有直接使用discord api,但是据我所知,我相信这会起作用.

Note I have not used discord api directly, but from what I know, I believe this will work.

我认为您发送DM就像在频道中发送消息一样.

I think you send a dm like sending a message in a channel.

您首先需要使用 https://discord.com创建dm./developers/docs/resources/user#create-dm

然后像任何普通频道一样发送给它 https://discord.com/developers/docs/resources/channel#create-消息

And then send to it like any normal channel https://discord.com/developers/docs/resources/channel#create-message

这篇关于使用Discord API在给定用户ID的情况下发送私人消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆