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.
23 Replies
Favna
Favna6mo ago
@vladdy
vladdy
vladdy6mo ago
huh, funky can you make a repro repo please @emo
Favna
Favna6mo ago
could it be that the command doesnt appear to be virtual @vladdy ?
vladdy
vladdy6mo ago
shouldn't be, because bun supports fs reading ConfusedEyes fixed that in latest version remember i mean I TRIED IT WITH new highlight and it just worked
emo
emo6mo ago
sure, not at home atm but as soon as I get there I'll create the repo Hey! I just figured it out lol So when you run bun init it generates the package.json file with the fields
"type": "module",
"module": "src/index,ts"
"type": "module",
"module": "src/index,ts"
if you change the module field to main it works. I'm not sure why or how that works, but it does lol
"type": "module",
"main": "src/index,ts"
"type": "module",
"main": "src/index,ts"
@vladdy sorry for pinging, but just so you know what I did
Favna
Favna6mo ago
I think I know why that happens I'll look into it
Favna
Favna6mo ago
@emo once that Pr is released the issue should be fixed
vladdy
vladdy6mo ago
that if check is useless
Favna
Favna6mo ago
I know, it's just code readability
vladdy
vladdy6mo ago
fair but its still useless the first part that is
Favna
Favna6mo ago
pushed
vladdy
vladdy6mo ago
favna do i need to teach you control meguFace
Favna
Favna6mo ago
no refresh
vladdy
vladdy6mo ago
Deadge
Favna
Favna6mo ago
@Favna chore: nobody had ever created a function like this one before.
Checks out
vladdy
vladdy6mo ago
i just love how theres multiple entrypoint possibilities in package.json
Favna
Favna6mo ago
ikr JS lanscape is so fantastic also hold on im gonna cover this function with unit tests
vladdy
vladdy6mo ago
its not needed
Favna
Favna6mo ago
but what if I want to
vladdy
vladdy6mo ago
doesnt change the fact its not needed OMEGALUL i aint stopping u have at it
Favna
Favna6mo ago
@emo in lieu of a final review on the PR you can already use the new version by setting the PR version in your package overrides/resolutions. @sapphire/pieces@pr-369
emo
emo6mo ago
sure, thanks