Moved system commands into /src/utils/ folder

This commit is contained in:
Marius Begby committed 2023-07-17 09:25:27 +02:00
1 parent 0a4ee5ff9f
commit 785354be6f
3 files changed
+2 -2

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
const path = require('path');
const fs = require('node:fs');
const logger = require(path.resolve('./src/services/logger.js'));
const { REST, Routes } = require('discord.js');
require('dotenv').config();
const commands = [];
const commandFiles = fs
.readdirSync(path.resolve('./src/commands'))
.filter((file) => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(path.resolve(`./src/commands/${file}`));
commands.push(command.data.toJSON());
}
const rest = new REST({ version: '10' }).setToken(
process.env.DISCORD_BOT_TOKEN
);
(async () => {
try {
logger.info('DEPLOYING BOT SLASH COMMANDS');
logger.info(
commands.map((commands) => {
return commands.name;
}),
'Bot commands found:'
);
logger.info('Started refreshing application (/) bot commands.');
await rest.put(
Routes.applicationCommands(process.env.DISCORD_CLIENT_ID),
{
body: commands
}
);
logger.info('Successfully refreshed application (/) bot commands.');
} catch (error) {
logger.error(error, 'Failed to refresh application (/) bot commands.');
}
})();
+53
View File
@@ -0,0 +1,53 @@
const path = require('path');
const fs = require('node:fs');
const logger = require(path.resolve('./src/services/logger.js'));
const { REST, Routes } = require('discord.js');
const { systemServerGuildIds } = require(path.resolve('./config.json'));
require('dotenv').config();
const systemCommands = [];
const systemCommandFiles = fs
.readdirSync(path.resolve('./src/system-commands'))
.filter((file) => file.endsWith('.js'));
for (const file of systemCommandFiles) {
const systemCommand = require(path.resolve(`./src/system-commands/${file}`));
systemCommands.push(systemCommand.data.toJSON());
}
const rest = new REST({ version: '10' }).setToken(
process.env.DISCORD_BOT_TOKEN
);
(async () => {
try {
logger.info('DEPLOYING SYSTEM SLASH COMMANDS');
logger.info(
systemCommands.map((systemCommand) => {
return systemCommand.name;
}),
'System commands found:'
);
logger.info('Started refreshing application (/) system commands.');
for (const systemServerGuildId of systemServerGuildIds) {
await rest.put(
Routes.applicationGuildCommands(
process.env.DISCORD_CLIENT_ID,
systemServerGuildId
),
{
body: systemCommands
}
);
}
logger.info('Successfully refreshed application (/) system commands.');
} catch (error) {
logger.error(
error,
'Failed to refresh application (/) system commands.'
);
}
})();