-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathDiscord.js
More file actions
27 lines (21 loc) · 873 Bytes
/
Discord.js
File metadata and controls
27 lines (21 loc) · 873 Bytes
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
const fetch = require('node-fetch')
const axios = require('axios')
const API_BASE_URL = 'https://discord.com/api/v10'
const CDN_BASE_URL = 'https://cdn.discordapp.com'
module.exports = class Discord {
static getWidget (guildId) {
return fetch(`${API_BASE_URL}/guilds/${guildId}/widget.json`).then(res => res.json())
}
static getInvite (inviteCode) {
return fetch(`${API_BASE_URL}/invites/${inviteCode}?with_counts=true`).then(res => res.json())
}
static fetchBase64Image (iconUrl) {
return fetch(iconUrl).then(res => res.buffer()).then(buffer => buffer.toString('base64'))
}
static getIconUrl (guildId, iconId) {
return `${CDN_BASE_URL}/icons/${guildId}/${iconId}${iconId.startsWith('a_') ? '.gif' : '.jpg'}`
}
static getSplashUrl (guildId, splashId) {
return `${CDN_BASE_URL}/splashes/${guildId}/${splashId}.jpg?size=480`
}
}