在discord4j 3.1.0版本中,ReactionEmojis是如何工作的?

huangapple go评论107阅读模式
英文:

How do ReactionEmojis work in discord4j 3.1.0

问题

  1. 我目前正在使用discord4j开发一个机器人,我想在消息中添加一个反应(表情符号)。
  2. 但是我完全不知道如何使用addReaction()方法,而且我找到的每个示例都是使用较旧的版本。
  3. 在早期版本的dicord4j中,您可以将表情符号的Unicode表示形式的字符串作为参数传递,但现在它只接受ReactionEmoji类型的对象。我查看了它的方法,除了ReactionEmoji.unicode(String raw)方法外,没有任何方法真正有意义。但是当我尝试使用ReactionEmoji.unicode(String raw)方法时,我收到了“未知表情符号”的错误消息。我尝试了Unicode、实际的表情符号本身,甚至进入了调试模式,在调试模式中添加了一个对消息的反应,然后在调试模式中获取了反应,并复制了反应的原始值,将其粘贴为unicode()方法的输入参数,但它仍然无法将其识别为表情符号。
  4. 是否有一些我找不到的文档?
  5. 我的代码:

Message msg = channel.createMessage("测试").block();
msg.addReaction("U+2B06").block();

  1. <details>
  2. <summary>英文:</summary>
  3. I&#39;m currently working on a bot with discord4j where I want to add a reaction(emoji) to a message.
  4. But i have no clue, how to use the addReaction() method and every example i find is using an older version.
  5. In earlier versions of dicord4j you could give a string of the unicode representation of the emoji as the parameter, but now it just takes in an object of the type ReactionEmoji. I looked at its methods nothing really makes sense except the ReactionEmoji.unicode(String raw) but then i get the error-message &quot;unknown emoji&quot;. As input of the string i tried the unicode, the actual emoji itself, and i went into debug mode, added a reaction to a message, then took the reaction in debug mode, and copied the raw value of the reaction, pasted it as the input parameter of the unicode() mehtod , but it still didn&#39;t recognize it as an emoji.
  6. Is there some documentation i can&#39;t find?
  7. My code :

Message msg = channel.createMessage("Test").block();
msg.addReaction("U+2B06").block();

  1. </details>
  2. # 答案1
  3. **得分**: 4
  4. 你必须使用[unicode escape][1]来替代:
  5. ```java
  6. channel.createMessage("Test")
  7. .flatMap(msg -> msg.addReaction(ReactionEmoji.unicode("\u2B06")))
  8. .subscribe();

有关文档,请参阅addReactionReactionEmoji

英文:

You have to use a unicode escape instead:

  1. channel.createMessage(&quot;Test&quot;)
  2. .flatMap(msg -&gt; msg.addReaction(ReactionEmoji.unicode(&quot;\u2B06&quot;)))
  3. .subscribe();

For documentation refer to addReaction and ReactionEmoji

答案2

得分: 0

  1. 对于多个反应
  2. channel.createMessage("Test").flatMap(msg ->
  3. msg.addReaction(ReactionEmoji.unicode("🚁"))
  4. .then(msg.addReaction(ReactionEmoji.unicode("🦲"))))
  5. .subscribe();
英文:

For multiple reactions

  1. channel.createMessage(&quot;Test&quot;).flatMap(msg -&gt;
  2. msg.addReaction(ReactionEmoji.unicode(&quot;&#128721;&quot;))
  3. .then(msg.addReaction(ReactionEmoji.unicode(&quot;&#129666;&quot;))))
  4. .subscribe();

huangapple
  • 本文由 发表于 2020年8月31日 00:30:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/63659649.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定