Skip to content

Preprogrammed scripts

Daniel Perales Mauriz edited this page Jun 10, 2022 · 14 revisions

This section describes the bot's ability to run preprogrammed scripts, which are located in the commands/tools/run.js file.
Below are the scripts that are integrated by default in the bot, but it is also possible to add new scripts.

Integrated scripts

The command to run these (and custom scripts as well) is /run <script name> [parameter/s] (as described in the Commands section).

Script name Parameter/s Description
welcome <@member | id> Forces the execution of the guildMemberAdd event for the specified member.
goodbye <@member | id> Forces the execution of the guildMemberRemove event for the specified member.

Add new scripts

Despite the fact that this bot is open-source and therefore you can make all the modifications you want to the code, I have designed this file specifically to execute small pieces of code and not alter the operation of the rest of the program in the process.

To add a new script, you'll need to add a new case to the switch statement that handles the execution of the scripts based on the interaction.options._hoistedOptions[0].value parameter, as follows:

switch (interaction.options._hoistedOptions[0].value) {
      case 'welcome':
              //Some code ...
              break;
      case 'goodbye':
              //Some code ...
              break;
      case 'yourNewScriptName':
              //Your new code will be here!
              break;
      default:
              //Some code ...
              break;
}

If you need to access parameters that the user provides, you will need to access the interaction.options._hoistedOptions[1] Object.
E.g. const parameters = interaction.options._hoistedOptions[1].value;

Clone this wiki locally