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 command
  • this.user.id - User ID
  • this.user.username - Username
  • this.user.tag - Username#1234
  • this.user.bot - Is bot?

Server Data

  • this.guild - Current server
  • this.guild.name - Server name
  • this.guild.memberCount - Member count
  • this.guild.ownerId - Owner ID
  • this.guild.roles - Roles collection

Channel Data

  • this.channel - Current channel
  • this.channel.name - Channel name
  • this.channel.type - Channel type
  • this.channel.send() - Send message

Bot Data

  • this.client - Discord.js client
  • this.client.user - Bot user
  • this.client.guilds - All servers
  • this.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
}]);