【问题标题】:GuildEmojis and UnicodeEmojis are not working well togetherGuildEmojis 和 UnicodeEmojis 不能很好地协同工作
【发布时间】:2020-11-24 12:22:18
【问题描述】:

我正在寻找 unicode 表情符号和自定义表情符号共同的东西。 假设我有一个 JSON 文件

{
     "emojis": ["something1", "something2", "something3"]
}

我的 discord.js 机器人现在应该将 messageReactionAdd-event 的表情符号与该数组的元素进行比较。可以说,如果表情符号与其中一个匹配,console.log("trigger") 应该会发生。但是代码并不重要。我找不到任何可以比较自定义表情符号和 Unicode 表情符号的共同点的东西。就像自定义表情符号有 ID 一样,unicode 没有,因此它有一个“图片”,比如????,自定义表情符号没有。有人有想法吗?

提前致谢!

【问题讨论】:

  • 我无法理解您的问题。你能试着重新制定一下吗?
  • 实际上,unicode emojis 也有一个“code”类型的东西。 console.log('????'.length)//2

标签: javascript node.js discord discord.js emoji


【解决方案1】:

为什么不同时存储 unicode 表情符号和自定义表情符号 ID?

emojis.json

{
  "emojis": ["?", "?", "?", "396548322053062656", "266241948824764416"];
}

bot.js

const emojis = require('emojis.json').emojis;

client.on('messageReactionAdd', (reaction, user) => {
  if (emojis.includes(reaction.emoji.name) || emojis.includes(reaction.emoji.id)) {
    console.log('Found emoji.');
  } else {
    console.log('Could not find emoji.');
  }
});

【讨论】:

  • 但是,当我使用 console.log(emoji.id) 时,我的自定义表情符号 ID 会显示出来,但对于 unicode,它会显示“null”
  • 或者你能告诉我✅的表情符号ID
  • 使用该表情符号发出事件并记录其 ID。如答案所述,discord.js 将为您返回 ID。
  • 我已经编辑了我的答案以提供不同的方法。
猜你喜欢
  • 2016-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-14
  • 2018-01-18
  • 1970-01-01
  • 2018-12-25
  • 2012-01-07
相关资源
最近更新 更多