所以我最近开始使用 JDA,并且在检测到消息已发送时没有任何问题。但由于某种原因,当它与附件相关时它不起作用。(是的,我在不和谐机器人设置中激活了意图)这是我的代码。
public void onMessageReceived(MessageReceivedEvent event) {
if (event.getAuthor().isBot()) return; // Ignore messages from other bots
suppressContentIntentWarning();
List<Attachment> attachments = event.getMessage().getAttachments();
TextChannel textChannel = event.getChannel().asTextChannel();
for (Attachment attachment : attachments) {
String fileName = attachment.getFileName();
String fileExtension = attachment.getFileExtension();
int size = attachment.getSize();
if (attachment.isImage()) {
textChannel.sendMessage("Image detected: " + fileName + ", size: " + size + " bytes").queue();
} else if (attachment.isVideo()) {
textChannel.sendMessage("Video detected: " + fileName + ", size: " + size + " bytes").queue();
} else {
textChannel.sendMessage("Other attachment detected: " + fileName + ", size: " + size + " bytes").queue();
}
}
}
ps:我查了一下,附件总是空的