Created
October 13, 2018 01:12
-
-
Save littletsu/7341def7aa482c42b02ba854681f5be4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// The command reloads other commands, using the command handler from our series | |
exports.run = (client, message, args, ops) => { | |
// We're going to be passing an extra argument, titled 'ops' | |
// We can choose what to pass into it via the server.js file | |
// Now, we can access ops.ownerID & it will return the ID defined at the top of server.js | |
// Check if author is the bot owner | |
if (message.author.id !== ops.ownerID) return message.channel.send('Sorry, only the owner can use this command.'); | |
// If the two IDs aren't the same, it will return and send a message to the channel | |
// Delete from cache | |
try { // This will be a try statment incase the command isn't found | |
delete require.cache[require.resolve(`./${args[0]}.js`)]; | |
// Since we're already in the commands folder, we won't need to specify it | |
} catch (e) { | |
// If we encounter an error, return & respond in chat | |
return message.channel.send(`Unable to reload: ${args[0]}`) | |
} | |
// Finally, send an output if it hasn't returned yet | |
message.channel.send(`Successfully reloaded: ${args[0]}`) | |
} // Now, we can test it! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment