From f96ebc560599ae1c4c94dd4bb7e88316c9f08436 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sun, 31 Mar 2024 00:30:51 -0400 Subject: [PATCH] Add reload-file command --- README.md | 2 +- commands/util/reload-file.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 commands/util/reload-file.js diff --git a/README.md b/README.md index df6689a1..a5968a46 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ If you self-host this you're nuts. 22. Run `pm2 start Xiao.js --name xiao` to run the bot. ## Commands -Total: 508 +Total: 509 ### Utility: diff --git a/commands/util/reload-file.js b/commands/util/reload-file.js new file mode 100644 index 00000000..02086877 --- /dev/null +++ b/commands/util/reload-file.js @@ -0,0 +1,35 @@ +const Command = require('../../framework/Command'); + +module.exports = class ReloadFileCommand extends Command { + constructor(client) { + super(client, { + name: 'reload-file', + group: 'util', + memberName: 'reload-file', + description: 'Reloads a file.', + details: 'Only the bot owner(s) may use this command.', + guarded: true, + ownerOnly: true, + args: [ + { + key: 'file', + type: 'string', + validate: file => { + try { + require.resolve(`../../${file}`); + return true; + } catch { + return false; + } + } + } + ] + }); + } + + run(msg, { file }) { + delete require.cache[require.resolve(`../../${file}`)]; + require(`../../${file}`); + return msg.say(`Reloaded \`${file}\`.`); + } +};