#Check if a custom emoji is a valid emoji my bot can use
14 messages · Page 1 of 1 (latest)
• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.
Tag suggestion for @karmic lion:
• For unicode emojis (twemoji): learn more
• Custom emojis: /<?(a)?:?(\w{2,32}):(\d{17,19})>?/ learn more
check if it matches this regex
I think I implemented it wrong because I have no idea of RegEx. Could you take a look at this please?
function checkDiscordEmoji(emoji) {
const regex = new RegExp("<?(a)?:?(\w{2,32}):(\d{17,19})>?")
return regex.test(emoji)
}
I don't know if your code is wrong or not but I'd do
function checkDiscordEmoji(emoji) {
const id = emoji.match(/<?(a)?:?(\w{2,32}):(\d{17,19})>?/)[3];
if (id) return id
return "The provided emoji is invalid."
}
It works but it crashes when I put in a normal emoji or just text
Says this:
const id = emoji.match(/<?(a)?:?(\w{2,32}):(\d{17,19})>?/)[3]
^
TypeError: Cannot read properties of null (reading '3')
this is what I do for my bot
That works way better but still crashes when you enter <noemoji
It's fixable with a try catch but now I'm facing the issue that it thinks that "<😂" is a valid emoji
Oh, I mixed things up. My function for checking normal emojis is just wrong because it just checks if a normal emoji is included. That's what passes the input. Not the custom emoji function. Thanks a lot for your help!