Sapphire - Imagine a framework
Sapphire - Imagine a framework

sapphire-support

Root Question Message

Rhys
Rhys1/30/2023
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`);
  }
}


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)
Rhys
Rhys1/30/2023
^ 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
Favna
Favna1/30/2023
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.
Rhys
Rhys1/30/2023
Will do thanks
Favna
Favna1/30/2023
Edited my first message so the whole blurb is in the answer
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy