emo
emo
SIASapphire - Imagine a framework
Created by emo on 12/21/2023 in #sapphire-support
Slash commands are not being registered when using Bun
Hello, I'm having trouble running the framework with bun because the slash commands are not being registered. I created a new empty project with bun init and then installed discord.js and @sapphire/framework My index.ts file, which is the entrypoint, looks like this:
import { SapphireClient } from "@sapphire/framework";
import { GatewayIntentBits } from "discord.js";

const client = new SapphireClient({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
],
});

(async () => {
try {
await client.login(process.env.BOT_TOKEN);
} catch (error) {
console.error(error);
client.destroy();
process.exit(1);
}
})();
import { SapphireClient } from "@sapphire/framework";
import { GatewayIntentBits } from "discord.js";

const client = new SapphireClient({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
],
});

(async () => {
try {
await client.login(process.env.BOT_TOKEN);
} catch (error) {
console.error(error);
client.destroy();
process.exit(1);
}
})();
and I have a directory commands with the file test.ts inside of it. this is what it looks like:
import { Command } from "@sapphire/framework";

export class TestCommand extends Command {
constructor(context: Command.LoaderContext, options: Command.Options) {
super(context, { ...options });
}

override registerApplicationCommands(registry: Command.Registry) {
console.log(">>> called registerApplicationCommands");
registry.registerChatInputCommand((builder) => {
console.log(">>> inside registerChatInputCommand callback");
return builder.setName("test").setDescription("hello world");
});
}

async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
return interaction.reply("hello world!");
}
}
import { Command } from "@sapphire/framework";

export class TestCommand extends Command {
constructor(context: Command.LoaderContext, options: Command.Options) {
super(context, { ...options });
}

override registerApplicationCommands(registry: Command.Registry) {
console.log(">>> called registerApplicationCommands");
registry.registerChatInputCommand((builder) => {
console.log(">>> inside registerChatInputCommand callback");
return builder.setName("test").setDescription("hello world");
});
}

async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
return interaction.reply("hello world!");
}
}
- I added the console.logs just to be sure that it actually wasn't being called. so when I run bun run src/index.ts this is the output I get:
[INFO] ApplicationCommandRegistries: Initializing...
[INFO] ApplicationCommandRegistries: Took 0ms to initialize.
[INFO] ApplicationCommandRegistries: Initializing...
[INFO] ApplicationCommandRegistries: Took 0ms to initialize.
and the command(s) never get registered, I even tried setting up the guildIds for a specific server for it to be faster, but it didn't work either. However, when I run the same code with node, the console.logs get printed to the terminal, and the commands are registered. This is the output running the same code with node:
[INFO] ApplicationCommandRegistries: Initializing...
>>> called registerApplicationCommands
>>> inside registerChatInputCommand callback
[INFO] ApplicationCommandRegistries: Took 2ms to initialize.
[INFO] ApplicationCommandRegistries: Initializing...
>>> called registerApplicationCommands
>>> inside registerChatInputCommand callback
[INFO] ApplicationCommandRegistries: Took 2ms to initialize.
43 replies