Command not Registering

So my command isint registering, here is the code
import { Command } from '@sapphire/framework';

export class KycCommand extends Command {
public constructor(context: Command.LoaderContext, options: Command.Options) {
super(context, {
...options,
enabled: true,
name: 'kyc',
description: 'Do Know-your-customer verification.',
});
}

public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand((builder) =>
builder //
.setName(this.name)
.setDescription(this.description)
.addUserOption((option) =>
option //
.setName('ign')
.setDescription('Your Minecraft IGN')
.setRequired(true)
)
);
}

public override async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
const mcIGN = interaction.options.getString('ign', true);

return await interaction.reply({
content: `MC Ign is: ${mcIGN}`,
});
}
}
import { Command } from '@sapphire/framework';

export class KycCommand extends Command {
public constructor(context: Command.LoaderContext, options: Command.Options) {
super(context, {
...options,
enabled: true,
name: 'kyc',
description: 'Do Know-your-customer verification.',
});
}

public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand((builder) =>
builder //
.setName(this.name)
.setDescription(this.description)
.addUserOption((option) =>
option //
.setName('ign')
.setDescription('Your Minecraft IGN')
.setRequired(true)
)
);
}

public override async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
const mcIGN = interaction.options.getString('ign', true);

return await interaction.reply({
content: `MC Ign is: ${mcIGN}`,
});
}
}
as a sanity check, I copied the ping example from the docs and it worked
Solution:
TL;DR: Do not use ts-node, use tsc-watch instead. We very strongly discourage using ts-node because it was never meant to be used for bots. ts-node is designed for REPL purposes. That's short for Read Eval Print Loop....
Jump to solution
16 Replies
torten
tortenOP5d ago
i then copied the registerApplicationCommands function from the ping command and it still wont register
Favna
Favna4d ago
any logging?
torten
tortenOP4d ago
Like the command being registered? No, i dont think thats turned on, and idk how to
Favna
Favna4d ago
there should be some logging in general when you start the bot it's on by default
torten
tortenOP4d ago
There is, lemme send it rq
torten
tortenOP4d ago
No description
Favna
Favna4d ago
ts-node.... hm.. what do you have set as main or module in your package.json? regardless:
Solution
Spinel
Spinel4d ago
TL;DR: Do not use ts-node, use tsc-watch instead. We very strongly discourage using ts-node because it was never meant to be used for bots. ts-node is designed for REPL purposes. That's short for Read Eval Print Loop. Which means to read some code, dump it in an eval() statement, print the result, and loop. A discord bot is not that. A Discord bot sets up a permanent web socket connection to the Discord server and connects to the rest gateway. There is read yes, but no eval, no print, and no loop. So what should you use instead? The most ideal way is to just use the watch flag of tsc (tsc --watch) and run node dist/index.js to run your bot, then cancel that process and restart it when you have changes that require restarting. You would open 2 terminal tabs, 1 in which you run tsc --watch and another in which you run the bot. This is, in particular, the most ideal way, because Discord has a limit to the amount of times you can log in with your bot, or register commands, per day. Constantly logging in over and over again due to an auto-restarting process will get you close to that limit very quickly and once you exceed it, your development will be halted entirely for the current day. However, this can be quite tedious so a great package to use instead is tsc-watch.
torten
tortenOP4d ago
hmmm
Favna
Favna4d ago
as for main/module
torten
tortenOP4d ago
"main": "dist/index.js", ill try this
Favna
Favna4d ago
yeah that's wrong if you're using ts-node because you're not compiling to dist it would have to be src/index.ts ergo dont use ts-node
torten
tortenOP4d ago
i see
vladdy
vladdy4d ago
if you wanna run your bot in ts, use bun, but you'll still need to update your main to point to src/index.ts
Favna
Favna4d ago
Agreed tbh
torten
tortenOP4d ago
i havent tried bun before, but ill take a look at it i guess

Did you find this page helpful?