-
Notifications
You must be signed in to change notification settings - Fork 3
The "e" object
e
is the name of the object given to a command when it's executed. It's constructor is DiscordBotMessage
. This is the most important object, and the one you'll use to access almost everything on the API. It contains information about the message that triggered your command, including user ID, server ID, channel ID, database access, and your constructed plugin.
There are several helper functions that make it very easy to respond to the message. These messages go on a queue, and are guaranteed to arrive in order.
These are all of the properties of the e object, with some basic info:
{
"_disco": "object", // DiscordBot object
"_mod": "string", // your plugin's name
"mod": "object", // constructed object from your plugin
"serverID": "string", // server this message was sent on
"user": "string", // user name
"userID": "string", //user ID
"channelID": "string", // channel ID
"message": "string", // the full message, unaltered
"rawEvent": "object", // the rawEvent object received from Discord.io
"db": "object", // database access object
"activator": "string", // the bot's name on the current server, e.g., "bot" in "bot say hi"
"globalActivator": "string", // the bot's name when not on a server (serverID = 0)
"_prepend": "string", // helper string, used by the response functions
"respond": "function", // send a text message
"respondFile": "function", // send a file
"mention": "function", // generate a mention
"text": "function", // add text
"code": "function", // add a code block
"n": "function", // add a new line
"getName": "function", // returns the name from an uid
"getUser": "function", // returns the user object on the current server, from Discord.io
"editMessage": "function", // edit a message by it's ID and channel
"getMod": "function", // returns the constructed object of another plugin
"command": "function", // executes a command by it's string
"deleteMessage": "function", // delete a message by id and channelID
"getRoles": "function", // returns user roles
"getRole": "function", // returns Discord.io role object
"roleName": "function" // returns the name of a role
}
The DiscordBot
object. Contains the command register, parsers, plugin manager, and all of the processing
Accessing this object directly is not recommended.
The name of your plugin, which is the same as it's folder name.
Your plugin object. Constructed once by calling new require("pluginName").init(e, callback)
.
You can store volatile information by setting it upon construction, and access it from any command. Using global variables within your plugin is not recommended. Store them on this object, and access it later.
The server ID where this message was sent. If this is a private message, this will be "0"
instead.
The user's name
The user's ID
You guessed it, the channel ID
The full message, as sent by the user.
May be an empty object if this command didn't originate from a message (e.g., called by e.command()
)
The Database Access object
The bot's 'name' on the current channel
The bot's 'name' on global channels
The current "buffer", used by the following functions to send messages
If message if a string, sends _prepend + message
on the channelID
. Clears _prepend
.
All callbacks are of the form callback(err, results)
, and the same as here
returns: e
. This means you can chain these functions by doing e.mention().respond("Hello");
Sends a file on the current channel, and clears _prepend
. file
should be a string
returns: e
Makes
_prepend += `<@${uid}> `;
If uid
is not given, uses e.userID
.
returns: e
_prepend += message;
returns: e
Generates a code block.
_prepend += "\```" + (lang || "") + "\n" + message + "\n\```"
returns: e
Adds a new line.
returns: e
Returns the username of UID.
Returns the user object on server sid
. Make uid = undefined
to default to e.userID
Edits a message. Make channelID = undefined
to default to e.channelID
.
You can get the id
from a response
callback (response.id).
Returns the plugin object of mod
, or undefined if not there.
Executes a command as e.user
on the current channel. Note that this may fail if the user doesn't have permission.
If you set rawEvent._extend
, you can replace properties on the e object sent to the command.
rawEvent = {
_extend: {
mod: e.mod
}
}
This is used by the live api to modify the response function on the passed e.
Deletes a message. If the first param is a function, deletes the message referenced by e.
returns: e
Returns the role objects for this user.
Returns the role object for this ID.
Returns only the role name.