From 4e1c41824623d94a79b4aaedc4daf8395991c03f Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Wed, 22 Sep 2021 19:54:49 +0100 Subject: [PATCH] Add ability to disable commands --- .env.template | 4 +++- README.md | 11 +++++++---- src/client/util.ts | 9 +++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.env.template b/.env.template index e27b438..2448e78 100644 --- a/.env.template +++ b/.env.template @@ -10,4 +10,6 @@ BOT_TOKEN= BOT_PREFIX=v! FOLDERS_COMMANDS=commands -FOLDERS_EVENTS=events \ No newline at end of file +FOLDERS_EVENTS=events + +COMMANDS_DISABLED= \ No newline at end of file diff --git a/README.md b/README.md index ccb9235..4f94096 100644 --- a/README.md +++ b/README.md @@ -14,12 +14,15 @@ BOT_PREFIX=v! FOLDERS_COMMANDS=commands FOLDERS_EVENTS=events + +COMMANDS_DISABLED= ``` -* **BOT_TOKEN:** Your bot's token, replace {TOKEN} with your bot token -* **BOT_PREFIX** The command prefix -* **FOLDERS_COMMANDS:** The folder which contains your commands -* **FOLDERS_EVENTS** The folder which contains your events +* **BOT_TOKEN:** Your bot's token, replace {TOKEN} with your bot token. +* **BOT_PREFIX:** The command prefix. +* **FOLDERS_COMMANDS:** The folder which contains your commands. +* **FOLDERS_EVENTS:** The folder which contains your events. +* **COMMANDS_DISABLED:** List of command file names that won't run, separated by commas. Make sure that you **DO NOT** put your .env file into VCS! diff --git a/src/client/util.ts b/src/client/util.ts index 311ec00..e1e1e58 100644 --- a/src/client/util.ts +++ b/src/client/util.ts @@ -22,6 +22,15 @@ export class Util { message: "Member is not part of message", }; + const disabledCommands = process.env.COMMANDS_DISABLED?.split(','); + + if (disabledCommands?.find(x => x == name)) { + return { + valid: false, + message: "Command is disabled", + }; + } + const folder = process.env.FOLDERS_COMMANDS; if (existsSync(`${process.cwd()}/${folder}/`)) {