#TypeError: registry.registerChatInputCommand is not a function

1 messages · Page 1 of 1 (latest)

left swiftBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

round fossil
#

i can share the files also

#

<@&737143830020620288>

crimson tinsel
#

show command code

late pawnBOT
#

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.

round fossil
#

w8

gritty sun
#

But more importantly what is your tsconfig

#

Assuming you have one

round fossil
#

w8 pls

gritty sun
#

This error often occurs when you haven't set a tsconfig target as it defaults to ES3 which removes class

pliant elbow
#
  "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)
                )
        );
    }
}```
crimson tinsel
#

the random acc switch aside

#

HandleAddStreamer is not a valid cmd

#

because of empty constructor

pliant elbow
#

becuase the nitro so i can send long msg

gritty sun
crimson tinsel
#

or gist.new

#

also

pliant elbow
#

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

crimson tinsel
#

theres physically no way for registry to not have that function Confusion

pliant elbow
#

u mean registerCommands.ts?

crimson tinsel
#

but that stacktrace is also very weird

#

are you manually calling those functions or?

pliant elbow
#

i tried gpt

#

which one xd

#

many errors

pliant elbow
#

the code was fine

crimson tinsel
#

the code is fine so you've done something wacky

pliant elbow
#

yeah but i dont remember

#

i was working on it all the day

#

xd

crimson tinsel
#

whats E:\VSC\riven.ts\src\bot.ts:78:24

pliant elbow
#

the main file

crimson tinsel
#

oh good god

#

no that is way wrong

pliant elbow
#

how chat gpt cant detect this lol

crimson tinsel
#

you shouldn't be blindly using chatgpt or alternatives meguFace

pliant elbow
#

its my frist time use Sapphire btw

crimson tinsel
#

you should not be trying to manually register these commands, sapphire handles it for you!

pliant elbow
#

i used to use

#

node registerCommands.js

gritty sun
#

Chatgpt and derivatives should only be used if you already know the subject so you can be critical about what it generates.

pliant elbow
#

but Sapphire handle it auto idk

crimson tinsel
#

lemme put it this way

#

you can basically remove all those listeners

gritty sun
#

https://sapphirejs.dev we recommend everyone to read the getting started guide