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

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

How do ReactionEmojis work in discord4j 3.1.0

问题

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

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


<details>
<summary>英文:</summary>

I&#39;m currently working on a bot with discord4j where I want to add a reaction(emoji) to a message.
But i have no clue, how to use the addReaction() method and every example i find is using an older version.
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.
Is there some documentation i can&#39;t find?
My code : 

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



</details>


# 答案1
**得分**: 4

你必须使用[unicode escape][1]来替代:

```java
channel.createMessage("Test")
       .flatMap(msg -> msg.addReaction(ReactionEmoji.unicode("\u2B06")))
       .subscribe();

有关文档,请参阅addReactionReactionEmoji

英文:

You have to use a unicode escape instead:

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

For documentation refer to addReaction and ReactionEmoji

答案2

得分: 0

对于多个反应

    channel.createMessage("Test").flatMap(msg ->
    msg.addReaction(ReactionEmoji.unicode("🚁"))
       .then(msg.addReaction(ReactionEmoji.unicode("🦲"))))
    .subscribe();
英文:

For multiple reactions

 channel.createMessage(&quot;Test&quot;).flatMap(msg -&gt; 
 msg.addReaction(ReactionEmoji.unicode(&quot;&#128721;&quot;))
                    .then(msg.addReaction(ReactionEmoji.unicode(&quot;&#129666;&quot;))))
.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:

确定