Emoji In Context Menu Command

Hey, I'm trying to put an emoji in a context menu command and it's throwing an error - is that expected? I'd expect emojis to work when registering the command, I'm guessing this might be a bug with the name validation that Sapphire does? Sample Code
import { ApplyOptions } from "@sapphire/decorators";
import { ChatInputCommand, Command, ContextMenuCommand } from "@sapphire/framework";
import {
ApplicationCommandType,
ContextMenuCommandBuilder,
ContextMenuCommandInteraction,
} from "discord.js";

@ApplyOptions<Command.Options>({
name: "Mark Solution",
runIn: ["GUILD_ANY"],
})
export class MarkSolution extends Command {
public override registerApplicationCommands(registry: ChatInputCommand.Registry) {
registry.registerContextMenuCommand(
new ContextMenuCommandBuilder()
.setName("✅ Mark Solution")
.setDMPermission(false)
.setType(ApplicationCommandType.Message)
);
}
public override contextMenuRun(
interaction: ContextMenuCommandInteraction,
context: ContextMenuCommand.RunContext
) {
return interaction.reply(`Marked ${interaction.targetId} as the solution`);
}
}
import { ApplyOptions } from "@sapphire/decorators";
import { ChatInputCommand, Command, ContextMenuCommand } from "@sapphire/framework";
import {
ApplicationCommandType,
ContextMenuCommandBuilder,
ContextMenuCommandInteraction,
} from "discord.js";

@ApplyOptions<Command.Options>({
name: "Mark Solution",
runIn: ["GUILD_ANY"],
})
export class MarkSolution extends Command {
public override registerApplicationCommands(registry: ChatInputCommand.Registry) {
registry.registerContextMenuCommand(
new ContextMenuCommandBuilder()
.setName("✅ Mark Solution")
.setDMPermission(false)
.setType(ApplicationCommandType.Message)
);
}
public override contextMenuRun(
interaction: ContextMenuCommandInteraction,
context: ContextMenuCommand.RunContext
) {
return interaction.reply(`Marked ${interaction.targetId} as the solution`);
}
}
Error:
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - Encountered error while handling the command application command registry for command "mark solution" at path "/workspace/apps/discord-bot/dist/commands/settings/mark-solution.js" ExpectedConstraintError > s.string.regex
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - Invalid string format
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR -
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - Expected: expected /^( *[\p{P}\p{L}\p{N}\p{sc=Devanagari}\p{sc=Thai}]+ *)+$/u.test(expected) to be true
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR -
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - Received:
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - | '✅ Mark Solution'
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR -
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - at Object.run (/workspace/node_modules/@sapphire/shapeshift/dist/index.js:1582:64)
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - at /workspace/node_modules/@sapphire/shapeshift/dist/index.js:201:66
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - at Array.reduce (<anonymous>)
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - at StringValidator.parse (/workspace/node_modules/@sapphire/shapeshift/dist/index.js:201:29)
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - at validateName (/workspace/node_modules/@discordjs/builders/dist/index.js:1480:18)
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - at ContextMenuCommandBuilder.setName (/workspace/node_modules/@discordjs/builders/dist/index.js:1516:5)
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - at MarkSolution2.registerApplicationCommands (/workspace/apps/discord-bot/dist/commands/settings/mark-solution.js:42:88)
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - at Object.handleRegistryAPICalls (/workspace/node_modules/@sapphire/framework/dist/lib/utils/application-commands/ApplicationCommandRegistries.js:39:23)
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - at processTicksAndRejections (node:internal/process/task_queues:96:5)
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - at async CoreEvent.run (/workspace/node_modules/@sapphire/framework/dist/listeners/CoreReady.js:18:5)
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - Encountered error while handling the command application command registry for command "mark solution" at path "/workspace/apps/discord-bot/dist/commands/settings/mark-solution.js" ExpectedConstraintError > s.string.regex
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - Invalid string format
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR -
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - Expected: expected /^( *[\p{P}\p{L}\p{N}\p{sc=Devanagari}\p{sc=Thai}]+ *)+$/u.test(expected) to be true
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR -
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - Received:
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - | '✅ Mark Solution'
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR -
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - at Object.run (/workspace/node_modules/@sapphire/shapeshift/dist/index.js:1582:64)
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - at /workspace/node_modules/@sapphire/shapeshift/dist/index.js:201:66
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - at Array.reduce (<anonymous>)
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - at StringValidator.parse (/workspace/node_modules/@sapphire/shapeshift/dist/index.js:201:29)
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - at validateName (/workspace/node_modules/@discordjs/builders/dist/index.js:1480:18)
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - at ContextMenuCommandBuilder.setName (/workspace/node_modules/@discordjs/builders/dist/index.js:1516:5)
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - at MarkSolution2.registerApplicationCommands (/workspace/apps/discord-bot/dist/commands/settings/mark-solution.js:42:88)
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - at Object.handleRegistryAPICalls (/workspace/node_modules/@sapphire/framework/dist/lib/utils/application-commands/ApplicationCommandRegistries.js:39:23)
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - at processTicksAndRejections (node:internal/process/task_queues:96:5)
@answeroverflow/discord-bot:dev: 2023-01-30 18:26:41 - ERROR - at async CoreEvent.run (/workspace/node_modules/@sapphire/framework/dist/listeners/CoreReady.js:18:5)
Solution:
I'd expect emojis to work when registering the command, I'm guessing this might be a bug with the name validation that Sapphire does?
Sapphire doesnt validate names. DiscordJS does. so you'll have to go there it's part of @discordjs/builders...
Jump to solution
4 Replies
Rhys
RhysOP2y ago
^ The ✅ Mark Solution command has an emoji in it, Discord.py allows for registering commands with emojis so I'm guessing it's a Sapphire bug
Solution
Favna
Favna2y ago
I'd expect emojis to work when registering the command, I'm guessing this might be a bug with the name validation that Sapphire does?
Sapphire doesnt validate names. DiscordJS does. so you'll have to go there it's part of @discordjs/builders For now you can bypass Shapeshift validation in builders with:
import { disableValidators } from 'discord.js';

disableValidator();
import { disableValidators } from 'discord.js';

disableValidator();
or use a yarn/pnpm patch (or patch-package for npm) to set this to .setValidationEnabled(false); https://github.dev/discordjs/discord.js/blob/main/packages/builders/src/interactions/slashCommands/Assertions.ts#L8-L12
Rhys
RhysOP2y ago
Will do thanks
Favna
Favna2y ago
Edited my first message so the whole blurb is in the answer

Did you find this page helpful?