JDA附件检测

问题描述 投票:0回答:1

所以我最近开始使用 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:我查了一下,附件总是空的

java maven bots discord-jda
1个回答
0
投票

既然你打电话给

suppressContentIntentWarning
,我就假设你没有按照警告去做。您必须在 JDA 的开发门户中启用意图。

有关详细信息,请参阅故障排除指南

© www.soinside.com 2019 - 2024. All rights reserved.