Mutiple Changes
- Added events loader and directory
This commit is contained in:
@@ -1,11 +0,0 @@
|
|||||||
const { REST } = require('@discordjs/rest');
|
|
||||||
const { Routes } = require('discord-api-types/v9');
|
|
||||||
//const { clientId, guildId, token } = require('./config.json');
|
|
||||||
|
|
||||||
const commands = [];
|
|
||||||
|
|
||||||
const rest = new REST({ version: '9' }).setToken(token);
|
|
||||||
|
|
||||||
rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands })
|
|
||||||
.then(() => console.log('Successfully registered application commands.'))
|
|
||||||
.catch(console.error);
|
|
||||||
28
events/interactionCreate.js
Normal file
28
events/interactionCreate.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
const { Events } = require('discord.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: Events.InteractionCreate,
|
||||||
|
async execute(interaction) {
|
||||||
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
|
||||||
|
const command = interaction.client.commands.get(interaction.commandName);
|
||||||
|
|
||||||
|
if (!command) {
|
||||||
|
console.error(`No command matching ${interaction.commandName} was found.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.DEBUG(`${interaction.member.user} is running '${interaction.commandName}'`);
|
||||||
|
|
||||||
|
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 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
43
index.js
43
index.js
@@ -91,7 +91,7 @@ function runHTTPServer() {
|
|||||||
server.on('error', libUtils.onError);
|
server.on('error', libUtils.onError);
|
||||||
|
|
||||||
server.on('listening', () => {
|
server.on('listening', () => {
|
||||||
log.INFO("Local HTTP Server Running");
|
log.INFO("HTTP server started!");
|
||||||
try {
|
try {
|
||||||
libCore.feedArray = libCore.getFeeds();
|
libCore.feedArray = libCore.getFeeds();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -115,43 +115,32 @@ for (const file of commandFiles) {
|
|||||||
client.commands.set(command.data.name, command);
|
client.commands.set(command.data.name, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run when the bot is ready
|
||||||
client.on('ready', () => {
|
client.on('ready', () => {
|
||||||
log.DEBUG(`Discord server up and running with client: ${client.user.tag}`);
|
log.DEBUG(`Discord server up and running with client: ${client.user.tag}`);
|
||||||
|
log.INFO(`Logged in as ${client.user.tag}!`);
|
||||||
|
|
||||||
// Deploy commands
|
// Deploy slash commands
|
||||||
log.DEBUG("Deploying commands");
|
log.DEBUG("Deploying slash commands");
|
||||||
deployCommands.deploy(client.guilds.cache.map(guild => guild.id));
|
deployCommands.deploy(client.guilds.cache.map(guild => guild.id));
|
||||||
|
|
||||||
log.DEBUG(`Starting HTTP Server`);
|
log.DEBUG(`Starting HTTP Server`);
|
||||||
runHTTPServer();
|
runHTTPServer();
|
||||||
|
|
||||||
log.INFO(`Logged in as ${client.user.tag}!`);
|
|
||||||
log.INFO("HTTP server started!");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on(Events.InteractionCreate, async interaction => {
|
// Setup any additional event handlers
|
||||||
if (!interaction.isChatInputCommand()) return;
|
const eventsPath = path.join(__dirname, 'events');
|
||||||
|
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
|
||||||
|
|
||||||
const command = interaction.client.commands.get(interaction.commandName);
|
for (const file of eventFiles) {
|
||||||
|
const filePath = path.join(eventsPath, file);
|
||||||
if (!command) {
|
const event = require(filePath);
|
||||||
console.error(`No command matching ${interaction.commandName} was found.`);
|
if (event.once) {
|
||||||
return;
|
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
|
client.login(discordToken); //Load Client Discord Token
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ exports.deleteSource = function (title, callback) {
|
|||||||
*/
|
*/
|
||||||
exports.getFeeds = function (feedType) {
|
exports.getFeeds = function (feedType) {
|
||||||
var linkFlayerFilteredMap = [];
|
var linkFlayerFilteredMap = [];
|
||||||
if (feedType == null || feedType == undefined || feedType == "") {
|
if (feedType == null || feedType == undefined || feedType == "" || feedType.toLowerCase() == "all") {
|
||||||
return rssFeedMap;
|
return rssFeedMap;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user