Skip to content
This repository has been archived by the owner on Feb 26, 2018. It is now read-only.

Creating new functions

Remco edited this page Dec 12, 2015 · 4 revisions

Creating new functions is fairly easily, just follow this example.

"<name-of-function>": {
        name: "<name_of_function_for_help>",
        description: "<description>",
        extendedhelp: "<more_info>",
        adminOnly: <true>,
        timeout: <time>,
        usage: "<usage-explanation>",
        process: function(<operators>) {
            bot.<function>;
        }
    }, 

<name-of-function> = Enter the name you want your users to execute.
<name_of_function_for_help> = This is the name that will be printed into !help
<description> = Enter a description for your command here, this will not be printed into !help
<more_info> = Enter even more information about the command here, this will be printed into !help
<usage> = If your command needs a suffix, describe it here, this will also be printed into !help
<function> = This is where you enter the code for the bot to execute, check the wiki from Discord.js for all of the functions the bot can execute.
adminOnly = Set this to true if you want to restrict this command to administrators, if you don't want this, remove this variable.
timeout = Define a timeout in seconds here, if you don't want a timeout, remove this variable.
<operators> = Enter the needed operators for the command here, the operators are:

  1. bot, This operator is always needed.
  2. msg, This operator is needed when the bot needs to send or receive a message.
  3. suffix, This operator is needed when the command can take a suffix.

Going with this example, here is the code for the !ping command.

    "ping": {
        description: "Responds pong, useful for checking if bot is alive.",
        name: "ping",
        extendedhelp: "I'll reply to you with ping, this way you can see if I'm still able to take commands.",
        process: function(bot, msg, suffix) {
            bot.sendMessage(msg.channel, " "+msg.sender+" pong!");
            if(suffix){
                bot.sendMessage(msg.channel, "note that !ping takes no arguments!");
            }
        }
    },
Clone this wiki locally