moved command register function to seperate file
This commit is contained in:
47
Commons/Commands.js
Normal file
47
Commons/Commands.js
Normal file
@ -0,0 +1,47 @@
|
||||
const fs = require('fs');
|
||||
const { REST, Routes } = require('discord.js');
|
||||
|
||||
/**
|
||||
* handles reactions in both ways
|
||||
* @param {string} Path path to Commands folder
|
||||
*/
|
||||
const Register = async (path) => {
|
||||
|
||||
if (typeof(path) != "string") {
|
||||
console.error("ERROR in commands.Register Commands path was not of type string")
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
if (path == "") {
|
||||
console.error("ERROR in commands.Register Commands path was not of type string")
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const commands = [];
|
||||
|
||||
/* ===============
|
||||
* File Import *
|
||||
=============== */
|
||||
const commandFiles = fs.readdirSync(path).filter((file) => file.endsWith(".js"));
|
||||
for (const file of commandFiles) {
|
||||
console.log(`loading: ${path}${file}`)
|
||||
const command = require(`.${path}${file}`);
|
||||
console.log(command.CommandCreator())
|
||||
commands.push(command.CommandCreator());
|
||||
}
|
||||
|
||||
console.log(commands)
|
||||
const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);
|
||||
(async () => {
|
||||
try {
|
||||
console.log('Started refreshing application (/) commands.');
|
||||
await rest.put(Routes.applicationCommands(process.env.APPID), { body: commands });
|
||||
console.log('Successfully reloaded application (/) commands.');
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
})();
|
||||
console.log("commands registered")
|
||||
}
|
||||
|
||||
module.exports = {Register}
|
3
index.js
3
index.js
@ -33,9 +33,6 @@ bot.on(Events.InteractionCreate, async interaction => {
|
||||
|
||||
// Handles Reactions
|
||||
bot.on(Events.MessageReactionAdd, async (reaction, user) => {
|
||||
console.log("reaction")
|
||||
console.log(reaction)
|
||||
console.log(reaction._emoji.name, reaction.message.id)
|
||||
HandleReaction(reaction, user, undefined, "add")
|
||||
})
|
||||
|
||||
|
33
sharding.js
33
sharding.js
@ -1,9 +1,9 @@
|
||||
// Include discord.js ShardingMana
|
||||
const { ShardingManager, REST, Routes, Events } = require('discord.js');
|
||||
const fs = require('fs');
|
||||
|
||||
// load .env config
|
||||
require("dotenv").config();
|
||||
const commands = [];
|
||||
|
||||
// Include discord.js ShardingMana
|
||||
const { ShardingManager} = require('discord.js');
|
||||
const { Register } = require("./Commons/Commands");
|
||||
|
||||
// Create your ShardingManager instance
|
||||
const manager = new ShardingManager("./index.js", {
|
||||
@ -13,27 +13,8 @@ const manager = new ShardingManager("./index.js", {
|
||||
token: process.env.TOKEN
|
||||
});
|
||||
|
||||
/* ===============
|
||||
* File Import *
|
||||
=============== */
|
||||
const commandFiles = fs.readdirSync("./Commands/").filter((file) => file.endsWith(".js"));
|
||||
for (const file of commandFiles) {
|
||||
const command = require(`./Commands/${file}`);
|
||||
console.log(command.CommandCreator())
|
||||
commands.push(command.CommandCreator());
|
||||
}
|
||||
|
||||
console.log(commands)
|
||||
const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);
|
||||
(async () => {
|
||||
try {
|
||||
console.log('Started refreshing application (/) commands.');
|
||||
await rest.put(Routes.applicationCommands(process.env.APPID), { body: commands });
|
||||
console.log('Successfully reloaded application (/) commands.');
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
})();
|
||||
// register slash commands
|
||||
Register("./Commands/")
|
||||
|
||||
// Emitted when a shard is created
|
||||
manager.on("shardCreate", shard => console.log(`Shard ${shard.id} launched`));
|
||||
|
Reference in New Issue
Block a user