Creating Commands

This page is a basic outline of how commands should be made in threecommands. Each command has its own separate file, inside the command directory specified in the previous page. This is an example of one command.

Code

module.exports.run = (bot, message, args, config) => {
    console.log(args);
    console.log(config);
    message.channel.send("Hello world! My name is " + bot.user.tag);
}

module.exports.help = {
    name: "helloworld"
}

Here, we see a run function, and a help object.

The run function is executed whenever the command is invoked. This command is invoked whenever somebody types (PREFIX)helloworld, where (PREFIX) is the prefix defined in the threecommands client. This function has four arguments: bot, which is the discord.js client in the context of the command, message, which is the message object in which the command was detected, args, which is an array of arguments after the command split up by spaces, and config which is the first argument that was passed to the threecommands client, containing your prefix, token, and directories.

The help function currently has only one key: the name. This is a string value which represents the name of the command internally, and what a user has to type after a prefix to invoke the run function.

Usage and Output

Assuming your bot is set up with a "!" as prefix, typing !helloworld one two three in a chat your bot can view will trigger this output:

Console

["one", "two", "three"]
{ prefix: "!",
  token: "discord_token_here",
  commandDir: "commands",
  eventDir; "events" }

Chat

Hello world! My name is name#discrim

results matching ""

    No results matching ""