Added system command support

This commit is contained in:
Marius Begby committed 2023-07-07 00:29:37 +02:00
1 parent 9feff8c62f
commit 64543752ae
1 file changed
+11 -3
+11 -3
View File
@@ -1,7 +1,7 @@
const fs = require('node:fs'); const fs = require('node:fs');
const Discord = require('discord.js'); const Discord = require('discord.js');
const { Player } = require('discord-player'); const { Player } = require('discord-player');
const { token } = require('./config.json'); const { token, embedColors } = require('./config.json');
// Setup required permissions for the bot to work // Setup required permissions for the bot to work
const client = new Discord.Client({ const client = new Discord.Client({
@@ -21,6 +21,14 @@ for (const file of commandFiles) {
client.commands.set(command.data.name, command); client.commands.set(command.data.name, command);
} }
const systemCommandFiles = fs
.readdirSync('./system-commands')
.filter((file) => file.endsWith('.js'));
for (const file of systemCommandFiles) {
const systemCommand = require(`./system-commands/${file}`);
client.commands.set(systemCommand.data.name, systemCommand);
}
// Create a new Player, and attach it to the bot client. // Create a new Player, and attach it to the bot client.
const player = new Player(client, { const player = new Player(client, {
ytdlOptions: { ytdlOptions: {
@@ -83,7 +91,7 @@ client.on('interactionCreate', async (interaction) => {
try { try {
await interaction.deferReply(); await interaction.deferReply();
await command.run({ interaction }); await command.run({ interaction, client });
console.log( console.log(
`Command '/${interaction.commandName}' was executed successfully.` `Command '/${interaction.commandName}' was executed successfully.`
); );
@@ -99,7 +107,7 @@ client.on('interactionCreate', async (interaction) => {
.setDescription( .setDescription(
`**Error**\nThere was an error while executing this command!\n\nIf this issue persists, please submit an issue in the support server: https://discord.gg/t6Bm8wPpXB` `**Error**\nThere was an error while executing this command!\n\nIf this issue persists, please submit an issue in the support server: https://discord.gg/t6Bm8wPpXB`
) )
.setColor('#c70057') .setColor(embedColors.colorError)
] ]
}); });
} }