【问题标题】:Is there a way to check if a message contains a Unicode emoji有没有办法检查消息是否包含 Unicode 表情符号
【发布时间】:2021-12-04 02:39:01
【问题描述】:

所以我试图制作一个投票命令它可以工作,但只有一个问题它不支持普通表情符号只是自定义表情符号这是我的代码

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}`)
}
}
  }

当我尝试使用普通表情符号时,它只是返回,你只能使用自定义表情符号等等等等我如何过滤自定义动画和普通表情符号,我让这个我不太擅长匹配和 Unicode 表情符号

【问题讨论】:

    标签: node.js discord.js


    【解决方案1】:

    如果您只想匹配移动的表情符号:

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

    匹配不动的自定义表情符号

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

    【讨论】:

      猜你喜欢
      • 2016-09-20
      • 1970-01-01
      • 2021-08-11
      • 2020-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-11
      相关资源
      最近更新 更多