英文:
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'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 "unknown emoji". 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't recognize it as an emoji.
Is there some documentation i can'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();
有关文档,请参阅addReaction和ReactionEmoji。
英文:
You have to use a unicode escape instead:
channel.createMessage("Test")
.flatMap(msg -> msg.addReaction(ReactionEmoji.unicode("\u2B06")))
.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("Test").flatMap(msg ->
msg.addReaction(ReactionEmoji.unicode("🛑"))
.then(msg.addReaction(ReactionEmoji.unicode("🪂"))))
.subscribe();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论