Seemingly Random Command Registration Failures

Hello there, I created a basic command, however whenever the bot refreshes, the command registration almost always fails. And this most recent time, the command registered, and then after a refresh, it failed to register again. Error:
2023-12-07 22:42:52 - ERROR - ApplicationCommandRegistries(BulkOverwrite) Failed to overwrite global application commands DiscordAPIError[50035]: Invalid Form Body
2023-12-07 22:42:52 - ERROR - 0.name[STRING_TYPE_REGEX]: String value did not match validation regex.
2023-12-07 22:42:52 - ERROR - at handleErrors (/home/ubuntu/bots/ef-bot/node_modules/.pnpm/@discordjs+rest@2.2.0/node_modules/@discordjs/rest/dist/index.js:722:13)
2023-12-07 22:42:52 - ERROR - at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2023-12-07 22:42:52 - ERROR - at async SequentialHandler.runRequest (/home/ubuntu/bots/ef-bot/node_modules/.pnpm/@discordjs+rest@2.2.0/node_modules/@discordjs/rest/dist/index.js:1120:23)
2023-12-07 22:42:52 - ERROR - at async SequentialHandler.queueRequest (/home/ubuntu/bots/ef-bot/node_modules/.pnpm/@discordjs+rest@2.2.0/node_modules/@discordjs/rest/dist/index.js:953:14)
2023-12-07 22:42:52 - ERROR - at async _REST.request (/home/ubuntu/bots/ef-bot/node_modules/.pnpm/@discordjs+rest@2.2.0/node_modules/@discordjs/rest/dist/index.js:1266:22)
2023-12-07 22:42:52 - ERROR - at async ApplicationCommandManager.set (/home/ubuntu/bots/ef-bot/node_modules/.pnpm/discord.js@14.14.1/node_modules/discord.js/src/managers/ApplicationCommandManager.js:171:18)
2023-12-07 22:42:52 - ERROR - at async handleBulkOverwrite (/home/ubuntu/bots/ef-bot/node_modules/.pnpm/@sapphire+framework@4.8.2/node_modules/@sapphire/framework/dist/lib/utils/application-commands/ApplicationCommandRegistries.js:82:20)
2023-12-07 22:42:52 - ERROR - at async Object.handleRegistryAPICalls (/home/ubuntu/bots/ef-bot/node_modules/.pnpm/@sapphire+framework@4.8.2/node_modules/@sapphire/framework/dist/lib/utils/application-commands/ApplicationCommandRegistries.js:56:5)
2023-12-07 22:42:52 - ERROR - at async _CoreListener.run (/home/ubuntu/bots/ef-bot/node_modules/.pnpm/@sapphire+framework@4.8.2/node_modules/@sapphire/framework/dist/listeners/CoreReady.js:17:5)
2023-12-07 22:42:52 - ERROR - at async Object.fromAsync (/home/ubuntu/bots/ef-bot/node_modules/.pnpm/@sapphire+result@2.6.4/node_modules/@sapphire/result/dist/index.js:613:22) {
2023-12-07 22:42:52 - ERROR - requestBody: [Object],
2023-12-07 22:42:52 - ERROR - rawError: [Object],
2023-12-07 22:42:52 - ERROR - code: 50035,
2023-12-07 22:42:52 - ERROR - status: 400,
2023-12-07 22:42:52 - ERROR - method: 'PUT',
2023-12-07 22:42:52 - ERROR - url: 'https://discord.com/api/v10/applications/1021449455628718120/commands'
2023-12-07 22:42:52 - ERROR - }
2023-12-07 22:42:52 - ERROR - ApplicationCommandRegistries(BulkOverwrite) Failed to overwrite global application commands DiscordAPIError[50035]: Invalid Form Body
2023-12-07 22:42:52 - ERROR - 0.name[STRING_TYPE_REGEX]: String value did not match validation regex.
2023-12-07 22:42:52 - ERROR - at handleErrors (/home/ubuntu/bots/ef-bot/node_modules/.pnpm/@discordjs+rest@2.2.0/node_modules/@discordjs/rest/dist/index.js:722:13)
2023-12-07 22:42:52 - ERROR - at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2023-12-07 22:42:52 - ERROR - at async SequentialHandler.runRequest (/home/ubuntu/bots/ef-bot/node_modules/.pnpm/@discordjs+rest@2.2.0/node_modules/@discordjs/rest/dist/index.js:1120:23)
2023-12-07 22:42:52 - ERROR - at async SequentialHandler.queueRequest (/home/ubuntu/bots/ef-bot/node_modules/.pnpm/@discordjs+rest@2.2.0/node_modules/@discordjs/rest/dist/index.js:953:14)
2023-12-07 22:42:52 - ERROR - at async _REST.request (/home/ubuntu/bots/ef-bot/node_modules/.pnpm/@discordjs+rest@2.2.0/node_modules/@discordjs/rest/dist/index.js:1266:22)
2023-12-07 22:42:52 - ERROR - at async ApplicationCommandManager.set (/home/ubuntu/bots/ef-bot/node_modules/.pnpm/discord.js@14.14.1/node_modules/discord.js/src/managers/ApplicationCommandManager.js:171:18)
2023-12-07 22:42:52 - ERROR - at async handleBulkOverwrite (/home/ubuntu/bots/ef-bot/node_modules/.pnpm/@sapphire+framework@4.8.2/node_modules/@sapphire/framework/dist/lib/utils/application-commands/ApplicationCommandRegistries.js:82:20)
2023-12-07 22:42:52 - ERROR - at async Object.handleRegistryAPICalls (/home/ubuntu/bots/ef-bot/node_modules/.pnpm/@sapphire+framework@4.8.2/node_modules/@sapphire/framework/dist/lib/utils/application-commands/ApplicationCommandRegistries.js:56:5)
2023-12-07 22:42:52 - ERROR - at async _CoreListener.run (/home/ubuntu/bots/ef-bot/node_modules/.pnpm/@sapphire+framework@4.8.2/node_modules/@sapphire/framework/dist/listeners/CoreReady.js:17:5)
2023-12-07 22:42:52 - ERROR - at async Object.fromAsync (/home/ubuntu/bots/ef-bot/node_modules/.pnpm/@sapphire+result@2.6.4/node_modules/@sapphire/result/dist/index.js:613:22) {
2023-12-07 22:42:52 - ERROR - requestBody: [Object],
2023-12-07 22:42:52 - ERROR - rawError: [Object],
2023-12-07 22:42:52 - ERROR - code: 50035,
2023-12-07 22:42:52 - ERROR - status: 400,
2023-12-07 22:42:52 - ERROR - method: 'PUT',
2023-12-07 22:42:52 - ERROR - url: 'https://discord.com/api/v10/applications/1021449455628718120/commands'
2023-12-07 22:42:52 - ERROR - }
Code:
import { ApplyOptions } from '@sapphire/decorators';
import { Command } from '@sapphire/framework';
import { ApplicationCommandType } from 'discord.js';

@ApplyOptions<Command.Options>({
description: 'Send the bug report template message to the user.'
})
export class UserCommand extends Command {
public constructor(context: Command.LoaderContext, options: Command.Options) {
super(context, { ...options });
}

public override registerApplicationCommands(registry: Command.Registry) {
registry.registerContextMenuCommand((builder) =>
builder //
.setName('bugtemplate')
.setType(ApplicationCommandType.Message)
);
}

// context menu command
public async contextMenuRun(interaction: Command.ContextMenuCommandInteraction) {
return await interaction.reply({ content: 'Hello', fetchReply: true });
}
}
import { ApplyOptions } from '@sapphire/decorators';
import { Command } from '@sapphire/framework';
import { ApplicationCommandType } from 'discord.js';

@ApplyOptions<Command.Options>({
description: 'Send the bug report template message to the user.'
})
export class UserCommand extends Command {
public constructor(context: Command.LoaderContext, options: Command.Options) {
super(context, { ...options });
}

public override registerApplicationCommands(registry: Command.Registry) {
registry.registerContextMenuCommand((builder) =>
builder //
.setName('bugtemplate')
.setType(ApplicationCommandType.Message)
);
}

// context menu command
public async contextMenuRun(interaction: Command.ContextMenuCommandInteraction) {
return await interaction.reply({ content: 'Hello', fetchReply: true });
}
}
Solution:
Ah issue was from an old issue in an old file that was still in the built files, so was still running
Jump to solution
3 Replies
Jellyton
Jellyton10mo ago
I see the "String value did not match validation regex." error, but the command name seems to be fine here, and it worked once before with that name.
Favna
Favna10mo ago
Remove the constructor. You cannot have both a constructor and @ApplyOptions. Other than that the validations that a context menu command name has to match are https://github.com/discordjs/discord.js/blob/main/packages/builders/src/interactions/contextMenuCommands/Assertions.ts#L6-L11
Solution
Jellyton
Jellyton10mo ago
Ah issue was from an old issue in an old file that was still in the built files, so was still running
Want results from more Discord servers?
Add your server