#TypeError: registry.registerChatInputCommand is not a function
1 messages · Page 1 of 1 (latest)
show command code
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.
w8
w8 pls
This error often occurs when you haven't set a tsconfig target as it defaults to ES3 which removes class
"compilerOptions": {
"target": "ESNext",
"module": "commonjs",
"strict": true,
"esModuleInterop": true, // Ensures compatibility with CommonJS and ES modules
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"noImplicitAny": false,
"allowJs": true,
"checkJs": false,
"strictNullChecks": true,
"baseUrl": "./",
"paths": {
"*": ["node_modules/*"],
"src/*": ["src/*"]
},
"outDir": "./dist"
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"**/*.test.ts"
]
}
import { Command } from '@sapphire/framework';
import { CommandInteraction } from 'discord.js';
import { addStreamer } from '../database/models';
// addStreamerCommand.ts
export class HandleAddStreamer {
constructor(private context: any, private options: any) {}
async chatInputRun(interaction: any) {
// Logic to handle adding a streamer
await interaction.reply(`Streamer added: ${this.options.name}`);
}
}
export class AddStreamerCommand extends Command {
constructor(context, options) {
super(context, {
...options,
name: 'add_streamer',
description: 'Add a new streamer',
});
}
async chatInputRun(interaction: CommandInteraction) {
const name = interaction.options.get('name')?.value as string;
const streamUrl = interaction.options.get('streamurl')?.value as string;
const liveUrl = interaction.options.get('liveurl')?.value as string;
const channelId = interaction.options.get('channelid')?.value as string;
const imageUrl = interaction.options.get('imageurl')?.value as string || ''; // Provide default empty string
const guildId = interaction.guildId as string;
// Basic validation
if (!streamUrl.includes('huya.com') || !liveUrl.includes('huya.com')) {
await interaction.reply({ content: 'Please provide valid URLs from huya.com', ephemeral: true });
return;
}
// Save to database
await addStreamer({
guildId,
name,
streamUrl,
liveUrl,
channelId,
imageUrl,
});
await interaction.reply({ content: `Streamer ${name} added successfully!`, ephemeral: true });
}
registerApplicationCommands(registry) {
registry.registerChatInputCommand(builder =>
builder
.setName(this.name)
.setDescription(this.description)
.addStringOption(option =>
option.setName('name')
.setDescription('Streamer Name')
.setRequired(true)
)
.addStringOption(option =>
option.setName('streamurl')
.setDescription('Stream URL')
.setRequired(true)
)
.addStringOption(option =>
option.setName('liveurl')
.setDescription('Live URL')
.setRequired(true)
)
.addStringOption(option =>
option.setName('channelid')
.setDescription('Discord Channel ID')
.setRequired(true)
)
.addStringOption(option =>
option.setName('imageurl')
.setDescription('Embed Image URL')
.setRequired(false)
)
);
}
}```
the random acc switch aside
HandleAddStreamer is not a valid cmd
because of empty constructor
becuase the nitro so i can send long msg
fyi you can also upload to a service like https://hastebin.skyra.pw
this what makes the excute quit/ exit
registry.registerChatInputCommand(builder =>
^
TypeError: registry.registerChatInputCommand is not a function
at AddStreamerCommand.registerApplicationCommands (E:\VSC\riven.ts\src\commands\addStreamerCommand.ts:50:18)
at _SapphireClient.<anonymous> (E:\VSC\riven.ts\src\bot.ts:78:24)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
how can i fix this u mean update npm or wut
theres physically no way for registry to not have that function 
u mean registerCommands.ts?
but that stacktrace is also very weird
are you manually calling those functions or?
.
the code was fine
the code is fine so you've done something wacky
whats E:\VSC\riven.ts\src\bot.ts:78:24
how chat gpt cant detect this lol
you shouldn't be blindly using chatgpt or alternatives 
its my frist time use Sapphire btw
you should not be trying to manually register these commands, sapphire handles it for you!
Chatgpt and derivatives should only be used if you already know the subject so you can be critical about what it generates.
but Sapphire handle it auto idk
https://sapphirejs.dev we recommend everyone to read the getting started guide