-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.js
21 lines (18 loc) · 1 KB
/
commands.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const { token } = require("./config")
const application_id = Buffer.from(token.split(".")[0], "base64").toString();
// https://discord.com/api/v10/applications/<my_application_id>/commands
async function registerGlobalCommand(command) {
return await fetch(`https://discord.com/api/v10/applications/${application_id}/commands`, {
method: "POST",
body: JSON.stringify(command),
headers: { Authorization: `Bot ${token}`, "Content-Type": "application/json" }
}).then(r => r.json());
}
async function sendInteractionResponse(interaction, response) {
return await fetch(`https://discord.com/api/v10/interactions/${interaction.id}/${interaction.token}/callback`, {
method: "POST",
body: JSON.stringify(response),
headers: { Authorization: `Bot ${token}`, "Content-Type": "application/json" }
}).then(async r => { let res = await r.text(); try { return JSON.parse(res) } catch { return res } });
}
module.exports = { registerGlobalCommand, sendInteractionResponse };