不在不和谐机器人上发送消息

时间:2021-02-17 05:22:22

标签: java maven intellij-idea discord-jda

我正在使用

  • IntelliJ 2020.3.2 Build 203.71487 社区版
  • Java 版本 15.0.1

我使用的是 maven 15。我有两个文件,第一个是 Main.Java,第二个是 cmds.jav

导入在那里,但我没有添加它们,因为我不希望它比它必须的更长 Main.java:

public class Main {

    public static String prefix = ";";

    public static void main(String[] args){
        start();
    }
    public static void start(){
        try {

            JDABuilder.create(("Token"), GatewayIntent.GUILD_EMOJIS, GatewayIntent.DIRECT_MESSAGE_REACTIONS, GatewayIntent.DIRECT_MESSAGES, GatewayIntent.DIRECT_MESSAGE_TYPING, GatewayIntent.DIRECT_MESSAGES, GatewayIntent.GUILD_BANS, GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_PRESENCES)
                .addEventListeners(new cmds())
                .setStatus(OnlineStatus.DO_NOT_DISTURB)
                .setActivity(Activity.playing("HELP ME"))
                .build();
        }catch (LoginException e){
            e.printStackTrace();
        }
    }
}

cmds.java:

public class cmds extends ListenerAdapter {
    @Override
    public void onMessageReceived(MessageReceivedEvent event) {

        String[] args = event.getMessage().getContentRaw().split("\\s+");

        if(args[0].equalsIgnoreCase(Main.prefix + "test")) {
            event.getChannel().sendMessage("Hi there!").queue();
        }
    }
}

活动和消息有效,但我无法让命令正常工作。我看过很多我最初使用 Gradle 的视频,但我无法真正让它工作,所以我从头开始使用 maven 并尝试遵循本指南:https://github.com/dawidekdevelopers/DiscordTutorial

控制台:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[main] WARN JDA - Automatically disabled CacheFlags due to missing intents
[main] WARN JDA - Disabled CacheFlag.VOICE_STATE (missing GatewayIntent.GUILD_VOICE_STATES)
[main] WARN JDA - You can manually disable these flags to remove this warning by using disableCache(CacheFlag.VOICE_STATE) on your JDABuilder
SLF4J: Failed to load class "org.slf4j.impl.StaticMDCBinder".
SLF4J: Defaulting to no-operation MDCAdapter implementation.
SLF4J: See http://www.slf4j.org/codes.html#no_static_mdc_binder for further details.
[main] INFO JDA - Login Successful!
[JDA MainWS-WriteThread] INFO WebSocketClient - Connected to WebSocket
[JDA MainWS-ReadThread] INFO JDA - Finished Loading!

0 个答案:

没有答案