[英]JDA 5 embed addreaction is incompatible types error
I have imported.net.dv8tion.jda.api.entities.emoji.Emoji and below is the code written我导入了.net.dv8tion.jda.api.entities.emoji.Emoji 下面是写的代码
EmbedBuilder embed = new EmbedBuilder();
embed.setColor(Color.green);
event.getChannel().sendTyping().queue();
event.getChannel().sendMessage("").setEmbeds(embed.build()).queue(message -> {
message.addReaction("✔").queue();
});
When running the code above, the error java: incompatible types: java.lang.String cannot be converted to.net.dv8tion.jda.api.entities.emoji.Emoji occurs.运行上述代码时,出现错误java: incompatible types: java.lang.String cannot be converted to.net.dv8tion.jda.api.entities.emoji.Emoji 。
You have to create an instance of Emoji
.您必须创建一个
Emoji
实例。 It offers various factory methods:它提供了多种工厂方法:
In your case, the string you have is a unicode emoji.在您的例子中,您拥有的字符串是 unicode 表情符号。 To use it as a reaction, simply wrap it in
Emoji.fromUnicode(...)
.要将其用作反应,只需将其包装在
Emoji.fromUnicode(...)
中。
Example: message.addReaction(Emoji.fromUnicode("✔")).queue()
示例:
message.addReaction(Emoji.fromUnicode("✔")).queue()
Note that you should also make sure that your files and compiler use UTF-8 if you directly paste emoji this way.请注意,如果您以这种方式直接粘贴表情符号,还应确保您的文件和编译器使用 UTF-8。 To avoid issues with encoding you can use the codepoint notation instead.
为避免编码问题,您可以改用代码点表示法。 You can find the codepoint notation by searching for
✔ unicode
on your search engine of choice.您可以通过在您选择的搜索引擎上搜索
✔ unicode
来找到代码点表示法。
Example: message.addReaction(Emoji.fromUnicode("U+2713")).queue()
示例:
message.addReaction(Emoji.fromUnicode("U+2713")).queue()
For performance reasons, it is recommended to store these emoji instances in static final fields.出于性能原因,建议将这些表情符号实例存储在 static 最终字段中。
public class Emojis {
public static final Emoji CHECKMARK = Emoji.fromUnicode("U+2713");
}
Then you can just use it like this: message.addReaction(Emojis.CHECKMARK).queue()
.然后你可以像这样使用它:
message.addReaction(Emojis.CHECKMARK).queue()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.