-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-commands.js
56 lines (47 loc) · 1.72 KB
/
deploy-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
import { REST } from '@discordjs/rest';
import { Routes } from 'discord-api-types/v10';
import config from "./config.json" assert { type: "json" };
import fs from 'node:fs';
import moment from "moment";
import { Client, GatewayIntentBits } from "discord.js";
const client = new Client({intents: [GatewayIntentBits.Guilds]});
const token = config.token;
const clientId = config.clientId;
const rest = new REST({ version: '10' }).setToken(token);
const log = x => { console.log(`[${moment().format("DD-MM-YYYY HH:mm:ss")}] ${x}`) };
client.login(token);
client.on("ready", async () => {
log(`${client.user.username} is ready!`);
const guilds = client.guilds.cache.map(guild => guild.id);
log(`Loaded guilds ${guilds}`);
log(`Loaded clientId ${clientId}`);
const commands = [];
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
log(`Loading command ${file}`);
try {
const { default: command } = await import(`./commands/${file}`);
commands.push(command.data.toJSON());
} catch (error) {
console.log(`Error loading command ${file}`);
console.error(error);
}
}
const commandData = commands.map(command => command);
(async () => {
try {
log('Started refreshing application (/) commands.');
for (const guildId of guilds) {
log(`Refreshing application (/) commands for guild ${guildId}`);
await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commandData },
);
}
log('Successfully reloaded application (/) commands.');
process.exit(0);
} catch (error) {
console.error(error);
}
})();
})