Mutiple Changes
- Added events loader and directory
This commit is contained in:
43
index.js
43
index.js
@@ -91,7 +91,7 @@ function runHTTPServer() {
|
||||
server.on('error', libUtils.onError);
|
||||
|
||||
server.on('listening', () => {
|
||||
log.INFO("Local HTTP Server Running");
|
||||
log.INFO("HTTP server started!");
|
||||
try {
|
||||
libCore.feedArray = libCore.getFeeds();
|
||||
} catch (error) {
|
||||
@@ -115,43 +115,32 @@ for (const file of commandFiles) {
|
||||
client.commands.set(command.data.name, command);
|
||||
}
|
||||
|
||||
// Run when the bot is ready
|
||||
client.on('ready', () => {
|
||||
log.DEBUG(`Discord server up and running with client: ${client.user.tag}`);
|
||||
log.INFO(`Logged in as ${client.user.tag}!`);
|
||||
|
||||
// Deploy commands
|
||||
log.DEBUG("Deploying commands");
|
||||
// Deploy slash commands
|
||||
log.DEBUG("Deploying slash commands");
|
||||
deployCommands.deploy(client.guilds.cache.map(guild => guild.id));
|
||||
|
||||
log.DEBUG(`Starting HTTP Server`);
|
||||
runHTTPServer();
|
||||
|
||||
log.INFO(`Logged in as ${client.user.tag}!`);
|
||||
log.INFO("HTTP server started!");
|
||||
});
|
||||
|
||||
client.on(Events.InteractionCreate, async interaction => {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
// Setup any additional event handlers
|
||||
const eventsPath = path.join(__dirname, 'events');
|
||||
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
|
||||
|
||||
const command = interaction.client.commands.get(interaction.commandName);
|
||||
|
||||
if (!command) {
|
||||
console.error(`No command matching ${interaction.commandName} was found.`);
|
||||
return;
|
||||
for (const file of eventFiles) {
|
||||
const filePath = path.join(eventsPath, file);
|
||||
const event = require(filePath);
|
||||
if (event.once) {
|
||||
client.once(event.name, (...args) => event.execute(...args));
|
||||
} else {
|
||||
client.on(event.name, (...args) => event.execute(...args));
|
||||
}
|
||||
|
||||
log.DEBUG(`${interaction.member.user} is running '${command}'`);
|
||||
|
||||
try {
|
||||
await command.execute(interaction);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
if (interaction.replied || interaction.deferred) {
|
||||
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
|
||||
} else {
|
||||
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
client.login(discordToken); //Load Client Discord Token
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user