Trying some upgrades to command loading

This commit is contained in:
Bradley Bickford 2023-12-31 09:39:25 -05:00
parent 7afbb169e2
commit 2f51c18a69
4 changed files with 23 additions and 8 deletions

View File

@ -26,29 +26,41 @@ const getAllFiles = function(directoryPath, arrayOfFiles) {
return arrayOfFiles;
};
const allFiles = [];
getAllFiles('.' + path.sep + 'commands', allFiles);
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildVoiceStates] });
client.commands = new Collection();
const commandFiles = allFiles.filter(file => file.endsWith('.js'));
//const commandFiles = allFiles.filter(file => file.endsWith('.js'));
var activeCalls = []
getAllFiles('.' + path.sep + 'commands', [])
.filter(file => file.endsWith('.js'))
.forEach(file => {
const command = require(file);
if ('enabled' in command && command.enabled && 'data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
console.log(`[INFO] Loaded command at ${file}`);
}
else {
console.log(`[WARNING] The command at ${file} is missing a required "data" or "execute" property or is not enabled.`);
}
});
/*
for (const file of commandFiles) {
const command = require(file);
if ('data' in command && 'execute' in command) {
if ('enabled' in command && command.enabled && 'data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
console.log(`[INFO] Loaded command at ${file}`);
}
else {
console.log(`[WARNING] The command at ${file} is missing a required "data" or "execute" property.`);
console.log(`[WARNING] The command at ${file} is missing a required "data" or "execute" property or is not enabled.`);
}
}
*/
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
@ -305,7 +317,7 @@ client.on(Events.MessageDelete, async deletedMessage => {
})
client.once(Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag}`);
console.log(`Ready! Logged in as ${c.user.tag} - ${c.user.id}`);
});
client.login(token);

View File

@ -1,6 +1,7 @@
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
enabled: true,
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),

View File

@ -1,6 +1,7 @@
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
enabled: true,
data: new SlashCommandBuilder()
.setName('server')
.setDescription('Provides information about the server.'),

View File

@ -1,6 +1,7 @@
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
enabled: true,
data: new SlashCommandBuilder()
.setName('user')
.setDescription('Provides information about the user.'),