A simple and lightweight custom function that can be used to create code blocks. An aoi.js version of codeBlock()
in Discord JS.
Usage
$codeBlock[content;lang?]
Parameters
content
: The content to wrap. (Required)
lang?
: The language for the code block. (Optional)
Source Code
Main File
<AoiClient>.functionManager.createFunction({
name: "$codeBlock",
type: "djs",
code: async function (d) {
let data = d.util.aoiFunc(d);
let [content, lang = ''] = data.inside.splits;
if (!content) {
d.aoiError.consoleError("Error", "Expecting valid string at 'content' field but found null");
return d.aoiError.fnError(d, 'custom', {}, 'Text Provided In Content Field.');
}
data.result = `\`\`\`${lang}\n${content}\`\`\``
return {
code: d.util.setCode(data)
}
}
});
Handler
module.exports = {
name: "$codeBlock",
type: "djs",
code: async function (d) {
let data = d.util.aoiFunc(d);
let [content, lang = ''] = data.inside.splits;
if (!content) {
d.aoiError.consoleError("Error", "Expecting valid string at 'content' field but found null");
return d.aoiError.fnError(d, 'custom', {}, 'Text Provided In Content Field.');
}
data.result = `\`\`\`${lang}\n${content}\`\`\``
return {
code: d.util.setCode(data)
}
}
}