This repository has been archived by the owner on Apr 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_commands.js
57 lines (47 loc) · 1.58 KB
/
init_commands.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* ====================NOTE====================
* This code was created by LostAndDead,
* please don't claim this as your own work
* https://github.com/LostAndDead
* ============================================
*/
const yaml = require('js-yaml');
const fs = require("fs");
const fetch = require("node-fetch")
const utils = require('./utils');
const { promisify } = require('util')
const sleep = promisify(setTimeout)
module.exports.sendCalls = async(bot, calls) => {
let Config = await utils.loadConfig()
if(!Config.Commands.SetupCommands){
return
}
let apiEndpoint
if (Config.Commands.JustGuildCommands) {
apiEndpoint = `https://discord.com/api/v8/applications/${bot.user.id}/guilds/${Config.Commands.GuildID}/commands`
console.log("Submitting commands to guild only")
}else {
apiEndpoint = `https://discord.com/api/v8/applications/${bot.user.id}/commands`
console.log("Submitting commands GLOBALY")
}
console.log("This will take a bit to avoiding rate limiting")
var x = 1
for(let command of calls){
await sleep(4000)
let res = await fetch(apiEndpoint, {
method: "post",
body: JSON.stringify(command),
headers: {
"Authorization": "Bot " + Config.Setup.Token,
"Content-Type": "application/json"
}
})
const json = await res.json()
if(json.code || json.message){
utils.log(json)
}else{
console.log(x + "/"+ calls.length)
x++
}
}
}