To begin with, there are two types of custom functions.
aoi.js
custom functions and djs
custom functions.
As you may can tell by the name aoi.js
custom functions include aoi.js functions, on the other side djs
refers to discord.js
which means it will create a discord.js custom function using discord.js functions/syntax.
bot.functionManager. createFunction ({
name: "$function" , // custom function name, can be anything.
params: [ "parameter" , ... ], // function parameters, $function[parameter;parameter]
type: "aoi.js" , // custom function type
code: "..." // the code that will be executed
Pretty simple example, and usage.
To return any parameter of params: [...]
you can use {name}
(name stands for the parameter name).
bot.functionManager. createFunction ({
name: "$function" , // custom function name, can be anything.
type: "djs" , // custom function type
code: ... // the code that will be executed
bot.functionManager. createFunction ({
code : async d => { // fetching data
const data = d.util. aoiFunc (d);
const [ parameter , ...] = data.inside.splits; // command parameters
data.result = ... // needed for the function to properly work, will set the "output" of the function
code: d.util. setCode (data) // will return the output from data.result
You can create error messages like the following;
For message errors:
aoiError. fnError (d, type, data, message);
For console errors:
aoiError. consoleError (name, e);
TYPE RETURNS member Invalid Member ID Provided In … message Invalid Message ID Provided In … channel Invalid Channel ID Provided In … user Invalid User ID Provided In … role Invalid Role ID Provided In … guild Invalid Guild ID Provided In … emoji Invalid Emoji ID Provided In … option Invalid Option ID Provided In … custom Invalid custom message
if ( ! parameter) return d.aoiError. fnError (d, "custom" , {}, "Custom Error Message" );
// will return a error message when the parameter "parameter" doesn't have any arguments.
Advanced Custom Functions Examples can be found here, some are useful others are more likely miscellaneous.
This section has been removed due to aoi.js custom functions being broken. We will update this section once aoi.js custom functions are fixed.
In this example we will create a custom function which sends an image as an attachment. The usage is as following:
bot.functionManager. createFunction ({
name: "$sendImage" , // our function name
type: "djs" , // notice how we don't need any params? that's the magic of JavaScript
const data = d.util. aoiFunc (d);
const [ URL ] = data.inside.splits; // our parameter of the function
const a = await d.message.channel. send ({
// send the attachment in the current channel
attachment: image // set the given URL as attachment
data.result = a; // set the "message" as result, to make aoi.js acknowledge it
code: d.util. setCode (data)