Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

How to modification

Elias Schaut edited this page Jan 31, 2022 · 5 revisions

Add a modicication

  1. Add a new JS file into mods folder and name it like your modification
  2. Copy the modification skeleton into the file
  3. Change the mod, like you want

Use a modicication

  1. Add the modification into a command as json element above the execution element (modifications below execution will be ignored) (example see in command skeleton)
  2. If the command is called, the check function all modifications will called. If one fails, the whole command will not executed and the send_check_fail function of the failed modification will be executed

Modification skeleton

// ----------------------------------
// config values
// ----------------------------------
const name = "<Name>"
const type = "<type>"
const required = false
// ----------------------------------
const error_key = "error." + name
const help_key = "mods_help." + name
// ----------------------------------


// ----------------------------------
// check msg
// ----------------------------------
async function check(msg, command, args) {
    const mod = await get(msg, command)
    return !mod || msg.client.helper.from_dm(msg)
}

async function send_check_fail(msg, command, args) {
    const err = await msg.client.lang_helper.get_text(msg, error_key)
    msg.client.output.reply(msg, err)
}
// ----------------------------------


// ----------------------------------
// check/get modification
// ----------------------------------
function is_valid(command) {
    const is_in_command = is_in(command)
    return (is_in_command || !required) && (!is_in_command || (typeof command[name] === type))
}

async function get(msg, command) {
    return (is_in(command)) ? command[name] : false
}

async function get_help(msg, command) {
    return await get(msg, command) ? await msg.client.lang_helper.get_text(msg, help_key) : ""
}

function is_in(command) {
    return command.hasOwnProperty(name)
}
// ----------------------------------

module.exports = { check, send_check_fail, is_valid, get, get_help, is_in, name, type, required }

Existing Command Modification Table

Key Description Value-Type Required
name The name of the command String + should be also the name of the file yes
description The description of the command. It will be shown in help command String yes
aliases Aliases for the command ['<String>', ..., '<String>'] no
args_needed If true, the command will only execute, if at least one argument is given. If args_min_length is set, the command needs at least this number of argument Boolean only if args_min_length is set
args_min_length The minimal number arguments, the command needs to be executed Number no
args_max_length The maximal number arguments, the command needs to be executed Number no
cooldown Sets a cooldown for only this command. The number stands for seconds Number no
cooldown_global Sets a globally for all commands. The number stands for seconds Number no
usage The description, how the arguments must look like String only if args_needed is set
guild_only If true the command runs only in guilds Boolean no
dm_only If true the command runs only in dms Boolean no
need_permission Users who want to execute the command need to have these permissions. ['<Discord-Permission>, ..., <Discord-Permission>'] (see Discord-Permissions) no
admin_only If true, only admins (see config file) can run this command Boolean no
nsfw If true, the command runs only in nfsw channels Boolean no
disabled If true, the command is not usable Boolean no
enable_slash If true, the command is addressable via slash-command Boolean no
Clone this wiki locally