使用Discord API发送给定用户ID的私有消息

2024-10-01 17:33:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在尝试使用Discord's API向用户发送一条新的私有消息,给定用户ID

我知道使用Discord.JS和Discord.py等库是可能的-请不要建议我使用这些库,我非常清楚我想要做什么。我曾尝试查看Discord.js等库的源代码,但似乎找不到使用特定用户创建新DM所需的端点

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

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

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请求,没有外部库),请让我知道,谢谢


Tags: 用户apiid消息jssome端点testing

热门问题