Is there a way to check if a message contains a Unicode emoji

Viewed 98

So im trying to make a poll command it works but there is just one problem it does not support normal emojis just custom emojis this is my code

const Discord = require("discord.js")
const { Permissions , MessageEmbed } = require("discord.js")
let wrong = "#F04A47"
module.exports = {
  name: "poll",
  usage: "poll <message>",
  description: "poll idk",
  category: "other",
  run: async (client, message, args) => {
    try {
         if(!message.member.permissions.has(Permissions.FLAGS.KICK_MEMBERS)) {
let embed = new MessageEmbed()
      .setDescription("**You do not have permissions to send polls/kick members**")
.setColor(wrong)
      return message.channel.send({embeds:[embed]})
    }
if(!args[0]) return message.channel.send("please type the first option example => $poll <pizza> <sushi> <> <>")
if(!args[1]) return message.channel.send("please type the second option example => $poll <pizza> <sushi> <> <>")
   
if(!args[2]) return message.channel.send("please type the first emoji example => $poll <pizza> <sushi> <> <>")

if(!args[3]) return message.channel.send("please type the second emoji example => $poll <pizza> <sushi> <> <>")

  const hasEmoteRegex = /<a?:.+:\d+>/gm
  const emoteRegex = /<:.+:(\d+)>/gm
  const animatedEmoteRegex = /<a:.+:(\d+)>/gm
  const normalemoji = /<::>/gm
      
if(args[3] && args[2].match(/<:\w+:[0-9]+>/)) { 
 const reportlog = new MessageEmbed()
 .setTitle('Poll Time ') 
 .setColor('RANDOM')
.setDescription(`${args[0]}${args[2]} or ${args[1]}${args[3]}`)
.setFooter(`Poll by ${message.author.tag}`)
.setTimestamp()
message.channel.send({embeds: [reportlog]}).then(sentMessage => {
 sentMessage.react(args[2])
 sentMessage.react(args[3])
 })
                                                   }
      else{
        message.channel.send("you can only use custom emojis for now ")
      }
 message.delete()
 } catch(e) {
message.channel.send(`an error occcured ${e}`)
}
}
  }

When i try to use a normal emoji it just return you can only use custom emojis blah blah blah how can i filter custom animated and normal emojis and i made this im not really good with matching and Unicode emojis

1 Answers

If you would like to only match moving emojis:

const animated = /<a:.+:(\d+)>/gm
if(message.match(animated)) {
  // do something...
}

Matching non-moving custom emojis

const animated = /<a:.+:(\d+)>/gm
const normal = /<::>/gm
if(message.match(normal) && !message.match(animated)) {
  // do something...
}
Related