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
Favna12mo ago
@vladdy
vladdy
vladdy12mo ago
huh, funky can you make a repro repo please @emo
Favna
Favna12mo ago
could it be that the command doesnt appear to be virtual @vladdy ?
vladdy
vladdy12mo 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
emoOP12mo 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
Favna12mo ago
I think I know why that happens I'll look into it
Favna
Favna12mo ago
@emo once that Pr is released the issue should be fixed
vladdy
vladdy12mo ago
that if check is useless
Favna
Favna12mo ago
I know, it's just code readability
vladdy
vladdy12mo ago
fair but its still useless the first part that is
Favna
Favna12mo ago
pushed
vladdy
vladdy12mo ago
favna do i need to teach you control meguFace
Favna
Favna12mo ago
no refresh
vladdy
vladdy12mo ago
Deadge
Favna
Favna12mo ago
@Favna chore: nobody had ever created a function like this one before.
Checks out
vladdy
vladdy12mo ago
i just love how theres multiple entrypoint possibilities in package.json
Favna
Favna12mo ago
ikr JS lanscape is so fantastic also hold on im gonna cover this function with unit tests
vladdy
vladdy12mo ago
its not needed
Favna
Favna12mo ago
but what if I want to
vladdy
vladdy12mo ago
doesnt change the fact its not needed OMEGALUL i aint stopping u have at it
Favna
Favna12mo 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
emoOP12mo ago
sure, thanks
Want results from more Discord servers?
Add your server