You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to allow my bot's users to customize part of a message in the bots posts. Per the design, the message can use emojis (including custom emojis), but not markdown (bold, italics, etc).
If I use the escapeMarkdown() method to clean the user input, sometimes an emoji can be escaped as well. This only happens if:
The emoji is a custom emoji
The custom emoji name has a "_" underscore in the name.
Take the following test scenarios:
lettestOne='This is a test with emojis <:FrostedWreath:1053399941210443826> and **bold text**.';letescapedTestOne=escapeMarkdown(testOne);console.log('Test 1:',escapedTestOne);lettestTwo='This is a test with emojis <:Frosted_Wreath:1053399939654352978> and **bold text**.';letescapedTestTwo=escapeMarkdown(testTwo);console.log('Test 2:',escapedTestTwo);
And the resulting output:
Test 1: This is a test with emojis <:FrostedWreath:1053399941210443826> and \*\*bold text\*\*.
Test 2: This is a test with emojis <:Frosted\_Wreath:1053399939654352978> and \*\*bold text\*\*.
In Test 1, the emoji was not escaped. In Test 2 the emoji was escaped because the name contains an underscore.
Side note: Channel mentions, role mentions, user mentions, follow a similar <some_discord_id> syntax as emojis, but these are not a problem with escaping markdown since they don't ever contain markdown characters like "_". Emoji mentions are unique in that they contain a name along with the ID, and that's what causes a problem with the escapeMarkdown() function. Slash command mentions may have a similar issue, I haven't tested that.
Ideal solution or implementation
Ideally escapeMarkdown() would have an option to include/exclude custom emojis from the escaping.
Alternative solutions or implementations
I can workaround this issue by writing a regex to find and remove all escape characters from emoji mentions after they have been escaped with escapeMarkdown().
Which package is the feature request for?
discord.js
Feature
I want to allow my bot's users to customize part of a message in the bots posts. Per the design, the message can use emojis (including custom emojis), but not markdown (bold, italics, etc).
If I use the
escapeMarkdown()
method to clean the user input, sometimes an emoji can be escaped as well. This only happens if:Take the following test scenarios:
And the resulting output:
In Test 1, the emoji was not escaped. In Test 2 the emoji was escaped because the name contains an underscore.
Side note: Channel mentions, role mentions, user mentions, follow a similar
<some_discord_id>
syntax as emojis, but these are not a problem with escaping markdown since they don't ever contain markdown characters like "_". Emoji mentions are unique in that they contain a name along with the ID, and that's what causes a problem with the escapeMarkdown() function. Slash command mentions may have a similar issue, I haven't tested that.Ideal solution or implementation
Ideally
escapeMarkdown()
would have an option to include/exclude custom emojis from the escaping.Alternative solutions or implementations
I can workaround this issue by writing a regex to find and remove all escape characters from emoji mentions after they have been escaped with
escapeMarkdown()
.Other context
Different behaviors after using escapeMarkdown depending on if the emoji name has an underscore in it:
The text was updated successfully, but these errors were encountered: