-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from stho32/main
A bunch of good ideas
- Loading branch information
Showing
7 changed files
with
119 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module.exports = { | ||
name: "interactionCreate", | ||
once: false, | ||
async execute(interaction) { | ||
if (!interaction.isCommand()) return; | ||
const command = client.commands.get(interaction.commandName); | ||
if (!command) return; | ||
|
||
try { | ||
await command.execute(interaction, client); | ||
} catch (error) { | ||
console.error(error); | ||
await interaction.reply({ | ||
content: "There was an error while executing this command!", | ||
ephemeral: true, | ||
}); | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module.exports = { | ||
name: "messageCreate", | ||
once: false, | ||
async execute(message) { | ||
if (message.author.bot) return; | ||
if (!message.guild) return; | ||
|
||
const args = message.content.slice(prefix.length).trim().split(/ +/); | ||
const commandName = args.shift().toLowerCase(); | ||
|
||
const command = | ||
client.commands.get(commandName) || | ||
client.commands.find( | ||
(cmd) => cmd.aliases && cmd.aliases.includes(commandName) | ||
); | ||
|
||
if (!command) return; | ||
|
||
try { | ||
command.run(message, args, client, prefix); | ||
} catch (error) { | ||
client.logger(error.message, "error"); | ||
embed.setDescription( | ||
"There was an error executing that command.\nI have contacted the owner of the bot to fix it immediately." | ||
); | ||
return message.channel.send({ embeds: [embed] }); | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/*** | ||
* CommandsHelper - Help for commands | ||
* | ||
* It may make no sense, but it is ours! | ||
*/ | ||
const fs = require("fs"); | ||
|
||
let commandsHelper = function () { | ||
let api = {} | ||
|
||
/** | ||
* Registers all commands in the given subdirectory into the client collection | ||
* | ||
* @param {string} commandsFolder Path to folder that contains all commands | ||
* @param {Client} client The discord client | ||
*/ | ||
api.registerAllCommands = function (commandsFolder, client) { | ||
const allCommandsFolders = fs.readdirSync(commandsFolder); | ||
|
||
for (const folder of allCommandsFolders) { | ||
const commandFiles = fs | ||
.readdirSync(`${commandsFolder}/${folder}`) | ||
.filter((file) => file.endsWith(".js")); | ||
for (const file of commandFiles) { | ||
const command = require(`${commandsFolder}/${folder}/${file}`); | ||
command.category = folder; | ||
client.commands.set(command.data.name, command); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Registers all events in the given subdirectory on the client | ||
* | ||
* @param {string} eventFolder Path to folder that contains all events | ||
* @param {Client} client The discord client | ||
*/ | ||
api.registerAllEvents = function (eventFolder, client) { | ||
const eventFiles = fs | ||
.readdirSync(eventFolder) | ||
.filter((file) => file.endsWith(".js")); | ||
|
||
for (const file of eventFiles) { | ||
const event = require(`${eventFolder}/${file}`); | ||
if (event.once) { | ||
client.once(event.name, (...args) => event.execute(...args)); | ||
} else { | ||
client.on(event.name, (...args) => event.execute(...args)); | ||
} | ||
} | ||
} | ||
|
||
return api; | ||
} | ||
|
||
module.exports.commandsHelper = commandsHelper(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters