Invalid Form Body (or at least something like that) When the bot tries to register a new command

Hello, I just started to continue on my bot. I just did a upgrade to the most recent version of discord.js and sapphire. But now, the bot started giving me after "boot" cringe errors telling me that he can't register the commands. Exactly: take a look on the screenshot, this **** ist too long! sapphire-version is "next". I use CommonJS btw, that was a previous error ๐Ÿ˜…
Solution:
its most likely to do with the fact that your providing the decorator and constructor. you have to provide one or the other, so you can either: - move your preconditions and cooldownDelay into the the decorator and remove the constructor - move your description into the constructor and remove the decorator...
Jump to solution
10 Replies
Durus
DurusOPโ€ข2y ago
BTW, the code of one of the commands is:
import { PrismaClient } from '@prisma/client';
import { ApplyOptions } from '@sapphire/decorators';
import { Command } from '@sapphire/framework';
const prisma = new PrismaClient();
@ApplyOptions<Command.Options>({
description: 'Some description.'
})
export class UserCommand extends Command {
public constructor(context: Command.Context) {
super(context, {
preconditions: ['admin', 'guildchannel'],
cooldownDelay: 10_000
});
}

public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand({
name: this.name,
description: this.description
});
}

public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { /* some code */}}} // I didn't count the brackets
import { PrismaClient } from '@prisma/client';
import { ApplyOptions } from '@sapphire/decorators';
import { Command } from '@sapphire/framework';
const prisma = new PrismaClient();
@ApplyOptions<Command.Options>({
description: 'Some description.'
})
export class UserCommand extends Command {
public constructor(context: Command.Context) {
super(context, {
preconditions: ['admin', 'guildchannel'],
cooldownDelay: 10_000
});
}

public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand({
name: this.name,
description: this.description
});
}

public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { /* some code */}}} // I didn't count the brackets
Solution
Seren_Modz 21
Seren_Modz 21โ€ข2y ago
its most likely to do with the fact that your providing the decorator and constructor. you have to provide one or the other, so you can either: - move your preconditions and cooldownDelay into the the decorator and remove the constructor - move your description into the constructor and remove the decorator
Krish
Krishโ€ข2y ago
Can you show the code for losungschannel command
Durus
DurusOPโ€ข2y ago
Okay, I'll try that as soon I'm home @Krish that is the code. Is that a new feature of the latest update? Because it worked until I did a upgrade to [email protected] ๐Ÿ˜… (and the latest sapphire version of course ๐Ÿ˜‰)
Seren_Modz 21
Seren_Modz 21โ€ข2y ago
it's not new, no. but u should never mix class decorators and constructors because your basically including two constructors
Durus
DurusOPโ€ข2y ago
Ok. I think I crossed two templates, I'll change this. I just removed the decorators from every command having a constructor. Sapphire stopped showing this error, and loads the commands properly, so I think this issue is done for now. Thanks @Seren_Modz 21 !!!
Krish
Krishโ€ข2y ago
well you should remove the contructor instead
Seren_Modz 21
Seren_Modz 21โ€ข2y ago
you can still use decorators but you would just have to remove the constructor. for example: https://github.com/sapphiredev/utilities/blob/main/packages/decorators/src/piece-decorators.ts#L15-L27
GitHub
utilities/piece-decorators.ts at main ยท sapphiredev/utilities
Common JavaScript utilities for Sapphire Projects. Contribute to sapphiredev/utilities development by creating an account on GitHub.
Seren_Modz 21
Seren_Modz 21โ€ข2y ago
maybe this will help visualize what i mean, whilst trying not to spoonfeed
public constructor(context: <Class>.Context) {
super(context, {
// you would move everything in this object, into the decorators object
// after moving everything, remove the whole of this constructor method
// leaving you with your decorator, registerApplicationCommands, chatInputRun and so on
});
}
public constructor(context: <Class>.Context) {
super(context, {
// you would move everything in this object, into the decorators object
// after moving everything, remove the whole of this constructor method
// leaving you with your decorator, registerApplicationCommands, chatInputRun and so on
});
}
Durus
DurusOPโ€ข2y ago
next time. I am glad that it is working now without having to code everything. But I'll write it on my TODO.
Want results from more Discord servers?
Add your server