Agent(data)

The main controlling agent of the bot

new Agent(data)

Create an Agent

Parameters:
Name Type Description
data Object

The agent data

Properties:
Name Type Attributes Default Description
data.Eris Eris

The Eris class the system runs off of

data.token String

The token to log in to the Discord API with

data.handlerData Object <optional>
{}

The commands and replacers the bot will respond to as well as options for their handlers

Properties
Name Type Attributes Default Description
commands Array<Command> | Command <optional>

The commands for the bot

reactCommands Array<ReactCommand> | ReactCommand <optional>

The commands that trigger on reactions

replacers Array<Replacer> | Replacer <optional>

The replacers for the bot

options Object <optional>
{}

Options for the event handlers

Properties
Name Type Attributes Default Description
prefix String <optional>
'!'

The prefix to execute commands

replacerBraces Object <optional>

The braces that invoke a replacer

Properties
Name Type Attributes Default Description
open String <optional>
'|'

The opening brace

close String <optional>

The closing brace

maxInterfaces Number <optional>
1500

The maximum amount of reaction interfaces cached before they start getting deleted

data.options Object <optional>
{}

Options for the agent

Properties
Name Type Attributes Default Description
intents Array<String> <optional>
[]

https://discord.com/developers/docs/topics/gateway#list-of-intents Additional intents to subscribe to for the gateway. (Intents are automatically calculated from agent features getting enabled. However, add additional intents if needed) (Eris supports snakeCase if CAMEL_CASE is not preferred)

guildOptions GuildData | Promise<GuildData> <optional>
{}

Options for specific guilds (Usually initially loaded from a database)

statusMessage Object | StatusMessageFunction <optional>

The status for the bot. It can be an object containing the data, or a callback function for each shard. By default, it's the bot's prefix

fireOnEdit Boolean <optional>
false

Whether the command handler is called when a command is edited or not

fireOnReactionRemove Boolean <optional>
false

Whether the reaction handler is triggered on the removal of reactions as well

postEventFunctions Object <optional>
{}

A collection of functions to run after an event is triggered

Properties
Name Type Attributes Description
message PostMessageFunction <optional>

A function that runs after every message whether it triggers a command or not

reaction PostReactionFunction <optional>

A function that runs after every reaction whether it triggers a react command or not

permission PostPermissionFunction <optional>

A function that runs after a permission is changed

prefix PostPrefixFunction <optional>

A function that runs after a guild prefix is changed

erisOptions Object <optional>
{}

A passthrough for additional Eris options. (Does not override intents, supply additional intents to options.intents)

Members

private _argTypeDescs : Object

Descriptions for argument types

private _assetURLs : Object

URLs to assets used internally

Properties:
Name Type Description
help String

The help icon

private _Eris : Class

The Eris class

private _guildData : GuildData

Guild specific data

private _handlerData : Object

The commands and replacers the bot will respond to as well as options for their handlers

Properties:
Name Type Description
commands Array<Command>

The commands for the command handler

reactCommands Array<ReactCommand>

The commands that trigger on reactions

replacers Array<Replacer>

The replacers for the command handler

options Object

The options for the handlers

Properties
Name Type Description
prefix String

The prefix to execute commands

replacerBraces Object

The braces that invoke a replacer

Properties
Name Type Description
open String

The opening brace

close String

The closing brace

maxInterfaces Number

The maximum amount of interfaces cached before they start getting deleted

private _helpCache : Array<String>

A cache for the buildHelp method

private _middleware : Array<Middleware>

Middleware to run during command processing

private _options : Object

The options for the agent

Properties:
Name Type Description
statusMessage Object | StatusMessageFunction

The status for the bot. It can be an object containing the data, or a callback function for each shard. By default, it's the bot's prefix

fireOnEdit Boolean

Whether the command handler is called when a command is edited or not

fireOnReactionRemove Boolean

Whether the reaction handler triggers on the removal of reactions

postEventFunctions Object

A collection of functions to run after an event is triggered.

Properties
Name Type Description
message PostMessageFunction

A function that runs after every message whether it triggers a command or not

reaction PostReactionFunction

A function that runs after every reaction whether it triggers a react command or not

permission PostPermissionFunction

A function that runs after a permission is changed

prefix PostPrefixFunction

A function that runs after a guild prefix is changed

app : Object

The Discord app of the bot

attachments : Object

User-supplied data that is passed to commands

client : Eris.Client

The Eris client

commandHandler : CommandHandler

The command handler for the bot

reactionHandler : ReactionHandler

The reaction handler for the bot

Methods

async, private _awaitGuildOptions(guildOptions)

Wait for guild options to be asynchronous supplied

Parameters:
Name Type Description
guildOptions Promise<GuildData>

The promise returning the data

private _bindBaseEvents()

Bind actions to base events

private _bindHandlerEvents()

Bind actions to events that require handlers

private _checkPermissions(msg, member, command)

Check if a user has the sufficient permissions to use a command

Parameters:
Name Type Description
msg Eris.Message

The message

member Eris.Member

The subject member of the guild

command Command | ReactCommand

The command

Throws:

private _compileInfo(items, header : opt) → {Array<String>}

Compile command info into a list

Parameters:
Name Type Attributes Description
items Array<Command> | Command | Array<Replacer> | Replacer | Array<ReactCommand> | ReactCommand

The items to compile

header String <optional>

The header of the content

Returns:
Array<String> -

The resulting info pages

private _formatPrefixesForHandler(data) → {Object}

Format guild data for command handler prefixes

Parameters:
Name Type Description
data GuilData

The data

Returns:
Object -

Returns an object where guild IDs are mapped to prefixes

private _getApp() → {Promise<Object>}

Get the bot's app data and store it in this.app

Returns:
Promise<Object> -

The app data

async, private _handleError(err, msg) → {Promise<(Message|void)>}

Send or log an error message if it's not an IgnoredError instance

Parameters:
Name Type Description
err Error

The error

msg Eris.Message

The original message from Discord

Returns:
Promise<(Message|void)>

private _initHandlers()

Initiate the event handlers

private _onError(error)

What to do when an unknown error occurs

Parameters:
Name Type Description
error Error

The error

async, private _onMessage(msg) → {Promise<void>}

What to do when a message is recived

Parameters:
Name Type Description
msg Eris.Message

The recieved message

Returns:
Promise<void>

async, private _onReaction(msg, emoji, userID) → {Promise<void>}

What to do when a reaction is recieved

Parameters:
Name Type Description
msg Eris.Message

The message reacted on

emoji Eris.Emoji

The emoji used to react

userID String

The ID of the user who reacted

Returns:
Promise<void>

private _onShardDisconnect(err, shard)

What to do when a shard loses connection

Parameters:
Name Type Description
err Error

The error

shard Eris.Shard

The disconnected shard

private _onShardReady(shardID)

What to do when a shard is ready

Parameters:
Name Type Description
shardID Number

The ID of the shard that's ready

private _prefixToken(token) → {String}

Prefix a token with the appropriate keyword designating a bot account if required

Parameters:
Name Type Description
token String

The token

Returns:
String -

The properly prefixed token

private _toArray(data) → {Array<*>}

Format data by turning existing single supply into arrays if necessary

Parameters:
Name Type Description
data * | Array<*>

The data

Returns:
Array<*> -

The formatted data

attach(name, value) → {Object}

Add an attachment that is passed to commands

Parameters:
Name Type Description
name String

The name of the attachment

value *

The value of the attachment

Returns:
Object -

All added attachments

generator buildCommandGuide(name)

Build a guide embed for a specific command (Does not work for replacers or react commands)

Parameters:
Name Type Description
name String

The name of the command

generator buildHelp(data : opt, page : opt)

Build a help menu and compile command info (Does not update with commands added after the agent has been constructed)

Parameters:
Name Type Attributes Default Description
data Object <optional>

The data for the menu

page Number <optional>
1

The page of the help menu to load

Properties:
Name Type Attributes Default Description
data.desc String <optional>

The description of the bot

data.serverCode String <optional>

The invite code to the bot's server (Note: This is the code, not the link)

data.color Number <optional>
33023

An integer color that changes the sidebar color of the embed

data.footerImage String <optional>

A link leading to an image for the footer (An image of the prefix recommended)

data.version String <optional>

The version of the bot

compileGuildSQL(dbData) → {GuildData}

Compile Knex-like guild data format to the Agent's native format

Parameters:
Name Type Description
dbData Array<Object>

The data from the database

Returns:
GuildData -

A formatted guild data object

Properties:
Name Type Attributes Default Description
dbData.id String

The ID of the guild

dbData.permissions PermissionList <optional>
{}

The authority level of the roles of the guild

dbData.prefix String <optional>

The custom server-side prefix

connect() → {Promise<void>}

Connect to the Discord API and initiate event handlers.

Returns:
Promise<void>

detach(name) → {*}

Remove an attachment

Parameters:
Name Type Description
name String

The name of the attachment to remove

Returns:
* -

The value of the removed attachment

getTopPermissionLevel(user) → {Number}

Get a guild member's top authority level role

Parameters:
Name Type Description
user Eris.Member

The member of the guild. (Do not provide an Eris User instance, it must be a Member)

Returns:
Number -

The leading authority level

lastMessage(channel) → {Eris.Message}

Get the last message sent by the bot in a given channel

Parameters:
Name Type Description
channel Eris.Channel

The ID of the channel to pick your last message from

Returns:
Eris.Message -

The last message

resetHelpCache()

Resets the help menu cache

setGuildPrefix(guild, prefix)

Set a server's custom prefix

Parameters:
Name Type Description
guild String

The ID of the guild

prefix String

The custom prefix

updatePermission(guild, role, level) → {Object}

Update the permission level of a guild role

Parameters:
Name Type Description
guild String

The ID of the guild

role String

The role to modify

level Number

The permission level to set the role to

Returns:
Object -

All current permissions of the guild