Skip to content

Event Utilities

When writing events for DaalBot, you have access to a variety of built-in utilities that help you interact with Discord and perform common tasks. These utilities are designed to make it easier to write event code without needing to import external modules.

We have an exported set of external libraries that you can use within your event code. Libraries such as discord.js (v14, stripped), node:crypto, and daalbot (stripped version of our internal APIs) are available for use.

This is a stripped version of discord.js v14, which provides the core functionality for interacting with the Discord API. Exported members are shown below:

{
builder: {
ModalBuilder: DJS.ModalBuilder,
TextInputBuilder: DJS.TextInputBuilder,
EmbedBuilder: DJS.EmbedBuilder,
ActionRowBuilder: DJS.ActionRowBuilder,
ButtonBuilder: DJS.ButtonBuilder,
StringSelectMenuOptionBuilder: DJS.StringSelectMenuOptionBuilder,
StringSelectMenuBuilder: DJS.StringSelectMenuBuilder,
TextDisplayBuilder: DJS.TextDisplayBuilder,
SeparatorBuilder: DJS.SeparatorBuilder,
SectionBuilder: DJS.SectionBuilder,
ThumbnailBuilder: DJS.ThumbnailBuilder,
MediaGalleryBuilder: DJS.MediaGalleryBuilder,
MediaGalleryItemBuilder: DJS.MediaGalleryItemBuilder,
ChannelSelectMenuBuilder: DJS.ChannelSelectMenuBuilder,
AttachmentBuilder: DJS.AttachmentBuilder,
ContainerBuilder: DJS.ContainerBuilder,
LabelBuilder: DJS.LabelBuilder
},
enum: {
TextInputStyle: DJS.TextInputStyle,
ChannelType: DJS.ChannelType,
ButtonStyle: DJS.ButtonStyle,
MessageFlags: DJS.MessageFlags,
SeparatorSpacingSize: DJS.SeparatorSpacingSize,
},
// Everything below here is legacy, kept for backwards compatibility, but new code should use the `builder` and `enum` namespaces above.
embed: DJS.EmbedBuilder,
components: {
row: DJS.ActionRowBuilder,
button: DJS.ButtonBuilder,
selectMenu: {
string: {
option: DJS.StringSelectMenuOptionBuilder,
builder: DJS.StringSelectMenuBuilder
}
}
}
}

This is the built-in Node.js crypto module, which provides cryptographic functionality such as hashing and encryption.

This is a stripped version of our internal DaalBot APIs, which provides various utilities for interacting with DaalBot features. Exported members are shown below:

{
tb: { // daalbot.api.pasteapi
createPaste: async(string) => Promise<string> // pasteapi_create_paste
}
}

This is a function that allows you to load extra external dependencies that are not included by default. You need to request access to specific modules by reaching out to us on our support server. Once granted, you can use the load function as shown below:

const axios = util.libraries.load('axios');

In addition to external libraries, we also provide some utility functions that help with common tasks.

You can use variables to store data that persists across event executions.

Setting a variable:

await util.variables.set('key', 'value', true); // (variableName, value, global) | 3rd option is "global" (whether to share variable across all events in the guild or not)

Getting a variable:

const value = await util.variables.get('key', true); // (variableName, global)

Modern DaalBot features use the managed database functionality, so there’s a uniform way to access and manipulate data.

Retrieving data:

const data = await util.db.get('inviteTracking.json'); // (path) | path is relative to the guild's managed database root

Storing data:

await util.db.set('inviteTracking.json', data); // (path, value)

Deleting data:

await util.db.delete('inviteTracking.json'); // (path)

Some DaalBot features provide their own APIs for interacting with them. These APIs are usually exposed via the util.features namespace.

This namespace (util.features.xp) provides methods for interacting with the XP system.

Retrieving a user’s XP data:

const xpData = await util.features.xp.get('1234567890123456789'); // (userId)

Setting a user’s XP data:

await util.features.xp.set('1234567890123456789', 1234); // (userId, xp - 1000xp = 1 level)

This namespace (util.features.welcomer) provides methods for interacting with the Welcomer feature.

Read the servers welcomer config:

const config = await util.features.welcomer.getConfig();

Output example:

{
"channel": "1234567890123456789", // Channel ID
"message": "Welcome to the server {user}!", // Message content
"embed": {
"title": "New member joined!",
"type": "rich",
"description": "This is member #{memberCount}.",
"url": null,
"timestamp": 0,
"color": null,
"fields": [],
"thumbnail": null,
"image": null,
"author": null,
"footer": null
}
}

Setting the channel:

await util.features.welcomer.setChannel('1234567890123456789'); // (channelId)

Setting the message:

await util.features.welcomer.setMessage('Welcome to the server {user}!'); // (message)

Setting the embed:

await util.features.welcomer.setEmbed({
title: "New member joined!",
type: "rich",
description: "This is member #{memberCount}.",
url: null,
timestamp: 0,
color: null,
fields: [],
thumbnail: null,
image: null,
}); // (embed)

This namespace (util.features.autorole) provides methods for interacting with the Autorole feature.

Checking if a role is in the autorole list:

const hasRole = await util.features.autorole.has('1234567890123456789'); // (role)

Adding a role to the autorole list:

await util.features.autorole.add('1234567890123456789'); // (role)

Removing a role from the autorole list:

await util.features.autorole.remove('1234567890123456789'); // (role)

Listing all autoroles:

const roles = await util.features.autorole.list(); // Returns an array of role IDs (string[])

This namespace (util.features.logging) provides methods for interacting with the Logging feature.

Checking if a certain log type is enabled:

const isEnabled = await util.features.logging.get('messageDelete'); // (logType - Discord gateway event name)

Toggling a certain log type:

await util.features.logging.set('messageDelete', true); // (logType - Discord gateway event name, enabled)

This namespace (util.features.tickets) provides methods for interacting with the Tickets feature.

The namespace util.features.tickets.legacy provides methods for interacting with the legacy Tickets feature.

Getting the category ID where tickets are created:

const categoryId = await util.features.tickets.legacy.getCategory();

Setting the category ID where tickets are created:

await util.features.tickets.legacy.setCategory('1234567890123456789'); // (categoryId)

Getting the permissions for newly created tickets:

const permissions = await util.features.tickets.legacy.getPermissions();

Permission object example:

[
{
"role": "1234567890123456789",
"action": "allow"
},
{
"role": "9876543210987654321",
"action": "deny"
}
]

Setting the permissions for newly created tickets:

await util.features.tickets.legacy.setPermissions('1234567890123456789', 'allow'); // (roleId, action - "allow" | "deny")