-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
36 lines (35 loc) · 1015 Bytes
/
index.js
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
34
35
36
import fetch from 'node-fetch';
export default class Webhook {
constructor(webhook_url) {
this.webhook_url = webhook_url + "?wait=true";
}
async send(username, avatar_url, content, embed) {
var parameters = {
username: username,
avatar_url: avatar_url,
content: content,
embeds: embed
}
fetch(this.webhook_url, {
method: "POST",
headers: {
'Content-type': 'application/json'
},
body: JSON.stringify(parameters)
}).then(res => {
if (res.status !== 200) { throw new Error(res.statusText); }
})
return this
}
async destroy() {
fetch(this.webhook_url, {
method: "DELETE",
headers: {
'Content-type': 'application/json'
},
}).then(res => {
if (res.status !== 204) { throw new Error(res.statusText); }
})
return this;
}
}