-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiscord.js
More file actions
33 lines (31 loc) · 1.15 KB
/
discord.js
File metadata and controls
33 lines (31 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* @typedef {{content:string,embeds:{title:string,description:string,color:Number,footer:{text:string,icon_url:string},author:{name:string,icon_url:string},fields:{name:string,value:string,inline:boolean}[],image:{url:string},thumbnail:{url:string}}}} DiscordMessage
*/
/**
* Sends a discord message through a webhook
* @param {DiscordMessage} message Message to send
* @param {string} webhookURL Webhook
*/
async function sendDiscordMessage(message, webhookURL) {
return await fetch(webhookURL, { headers: { "Content-Type": "application/json" }, method: "POST", body: JSON.stringify(message) })
}
/**
* Gets a discord webhook
* @param {string} webhookURL Webhook
* @returns {{avatarUrl:string,name:string}|undefined} Useful stuff
*/
async function getDiscordWebhook(webhookURL) {
let error = false
let data = await fetch(webhookURL)
.then(p=>{
if (p.status === 200) {return p.json()}
else {error = true}
})
.catch(e=>console.error(e))
if (error) return
if (data === undefined || data === null) return
return {
avatarUrl: (data.avatar!==null)?`https://cdn.discordapp.com/avatars/${data.id}/${data.avatar}?size=256`:null,
name: data.name,
}
}