I have been attempting to use Discord's API to send a new private message to a user, given their user ID.
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.
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
},
})
If anyone knows the proper endpoint or another way to achieve this(using purely POST requests, no external libraries), please let me know, thanks.
Note I have not used discord api directly, but from what I know, I believe this will work.
I think you send a dm like sending a message in a channel.
You first need to create the dm using https://discord.com/developers/docs/resources/user#create-dm
And then send to it like any normal channel https://discord.com/developers/docs/resources/channel#create-message
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments