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).
client.functionManager. createFunction ({
name: "$function" , // custom function name, can be anything.
type: "djs" , // custom function type
code: ... // the code that will be executed
client.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.
A fix has been implemented in 6.8.10 which will be released in the near future.
In this example we will create a custom function which sends an image as an attachment. The usage is as following:
// we need this for our function!
const { AttachmentBuilder } = require ( "discord.js" );
client.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);
if (data.err) return d. error (data.err); // we can make this function require arguments, if user doesnt pass one itll throw an error message
const [ URL , name = "image.png" ] = data.inside.splits; // our parameter of the function, image has a default value "image.png" therefore making it optional
const result = new AttachmentBuilder (
? Buffer. from (image. addBrackets ())
{ name: name. addBrackets () }
d.files. push (result); // pushing our file to make aoijs "register it"
// we COULD send it directly, but this would break other file related commands!
code: d.util. setCode (data),