Context API
Access Discord data and utilities inside command handlers via this.
Interaction Methods
Respond to user interactions:
this.reply()
// Simple text
await this.reply('Hello!');
// With embed
await this.reply({
embeds: [{
title: 'Title',
description: 'Description'
}]
});
// Ephemeral (only user sees)
await this.reply({
content: 'Secret message',
flags: 64 // Ephemeral flag
});
this.edit()
Update a previous reply:
await this.reply('Processing...');
// Do some work
await this.edit('Done!');
this.defer()
For operations taking more than 3 seconds:
await this.defer(); // Shows "thinking..."
// Do long operation
await someSlowFunction();
await this.edit('Finished!');
this.followUp()
Send additional messages:
await this.reply('First message');
await this.followUp('Second message');
await this.followUp('Third message');
this.update()
For button interactions:
onButton('confirm', async function() {
await this.update('Confirmed!');
});
Data Access
User Data
this.user- User who ran commandthis.user.id- User IDthis.user.username- Usernamethis.user.tag- Username#1234this.user.bot- Is bot?
Server Data
this.guild- Current serverthis.guild.name- Server namethis.guild.memberCount- Member countthis.guild.ownerId- Owner IDthis.guild.roles- Roles collection
Channel Data
this.channel- Current channelthis.channel.name- Channel namethis.channel.type- Channel typethis.channel.send()- Send message
Bot Data
this.client- Discord.js clientthis.client.user- Bot userthis.client.guilds- All serversthis.client.uptime- Uptime (ms)
Parameter Getters
Get command parameters safely:
commands/test.js
bot.command.new('test', 'Test params', async function() {
// Get parameters
const text = this.getString('message');
const num = this.getInteger('count');
const user = this.getUser('target');
const channel = this.getChannel('destination');
const role = this.getRole('role');
const bool = this.getBoolean('enabled');
// All getters return null if not provided
if (!user) {
return await this.reply('No user specified!');
}
await this.reply(`User: ${user.username}`);
}, [
{ name: 'message', type: 3, description: 'Text', required: true },
{ name: 'count', type: 4, description: 'Number', required: false },
{ name: 'target', type: 6, description: 'User', required: false },
// ... more parameters
]);
Built-in Utilities
Random Utilities
// Random number
const dice = this.random.number(1, 6);
// Random boolean
const coinFlip = this.random.bool();
// Pick from array
const choice = this.random.pick(['red', 'blue', 'green']);
// Random character from range
const letter = this.random.string('A to Z');
Time Utilities
// Relative time (5 minutes from now)
const future = this.time.parse('+5');
// Absolute time (5:30 PM today)
const specific = this.time.parse('17.30');
// Current time
const now = this.time.now();
// Unix timestamp
const unix = this.time.unix(now);
Custom Data
// Access emoji
await this.reply(`${this.emoji.wave} Hello!`);
// Access global values
const botName = this.vals.bot.name;
const primaryColor = this.vals.colors.primary;
Complete Example
commands/userinfo.js
bot.command.new('userinfo', 'Get user information', async function() {
// Get user parameter or default to command user
const target = this.getUser('user') || this.user;
// Calculate account age
const created = target.createdAt;
const age = Math.floor((Date.now() - created.getTime()) / (1000 * 60 * 60 * 24));
// Send embed with all info
await this.reply({
embeds: [{
author: {
name: target.username,
icon_url: target.displayAvatarURL()
},
thumbnail: {
url: target.displayAvatarURL({ size: 256 })
},
fields: [
{ name: 'ID', value: target.id },
{ name: 'Tag', value: target.tag },
{ name: 'Bot?', value: target.bot ? 'Yes' : 'No', inline: true },
{ name: 'Account Age', value: `${age} days`, inline: true }
],
footer: { text: `Requested by ${this.user.username}` },
timestamp: new Date(),
color: this.vals.colors.primary
}]
});
}, [{
name: 'user',
description: 'User to get info about',
type: 6,
required: false
}]);