Command
You can create new commands in app/commands
Decorator
Decorator
parameter
type
required
cooldown
number
guilds
string[]
builder
any
You can specify guilds by their ids as an array. ["1", "2", "3"]
or ["*"]
Template
Template
import { Client, CommandInteraction, SlashCommandBuilder } from "discord.js";
import { Command } from "engine";
@Command(5, ["*"], new SlashCommandBuilder().setName("ping").setDescription("Replies with Pong!"))
export default class PingCommand {
public static async callback(client: Client, interaction: CommandInteraction) {
await interaction.reply("Pong!");
}
}
Permissions
Permissions
import { Client, CommandInteraction, SlashCommandBuilder, PermissionFlagsBits } from "discord.js";
import { Command } from "engine";
@Command(5, ["*"], new SlashCommandBuilder().setName("ping").setDescription("Replies with Pong!"))
export default class PingCommand {
public static async callback(client: Client, interaction: CommandInteraction) {
if (!interaction.memberPermissions?.has(PermissionFlagsBits.SendMessages)) {
await interaction.reply({ content: "You do not have the required permissions to use this command.", ephemeral: true });
return;
}
await interaction.reply("Pong!");
}
}
You can use PermissionFlagsBits
(all permissions)
Globals
(only available to commands)
Globals
(only available to commands)Definition
export const globals = {
some_variable: "test",
};
Usage
client.globals.get("COMMAND_NAME")
Example
import { Client, CommandInteraction, SlashCommandBuilder, PermissionFlagsBits } from "discord.js";
import { Command } from "engine";
export const globals = {
some_variable: "test",
};
@Command(5, ["*"], new SlashCommandBuilder().setName("ping").setDescription("Replies with Pong!"))
export default class PingCommand {
public static async callback(client: Client, interaction: CommandInteraction) {
const ping_globals = client.globals.get("ping")
console.log(ping_globals.some_variable) // will log: test
await interaction.reply("Pong!");
}
}
Options
Options
import { Client, CommandInteraction, SlashCommandBuilder, PermissionFlagsBits } from "discord.js";
import { Command, CommandOptions } from "engine";
export const globals = {
some_variable: "test"
}
@Command(5, ["*"], new SlashCommandBuilder().setName("ping").setDescription("Replies with Pong!"))
export default class PingCommand {
public static async callback(client: Client, interaction: CommandInteraction, options: CommandOptions) {
const cooldown = options.cooldown; // is: 3
const command_name = options.data.name; // is: ping
// get current global variables
const globals = client.globals.get(command_name);
console.log(globals.some_variable); // is: test
await interaction.reply("Pong!");
}
}
Last updated