1.15.2 Gradle JDA

Discussion in 'Spigot Plugin Development' started by Ardno, Feb 27, 2020.

  1. Hello,
    I'm making a spigot plugin with JDA, but I have a problem.
    Code (Java):
    public class BadBot {
        public static JDABuilder builder;

        public static void setup() {
            try {
                builder = new JDABuilder(AccountType.BOT);
                builder.setToken("TokenForBot-IHideIt");
                builder.setStatus(OnlineStatus.ONLINE);
                builder.setActivity(Activity.listening(" svého tvůrce Ardna"));
                builder.build();
            } catch(LoginException e) {
                System.out.println("LoginExceotion");
            }

            registerEvents();
        }

        private static void registerEvents() {
            builder.addEventListeners(new ChatEvent());
        }
    }
    Bot has normal started. But if I send message, the broadcast doesn't work. Mby it's problem in registerEvents().
    ChatEvent:
    Code (Java):
    public class ChatEvent extends ListenerAdapter {
        Main plugin = JavaPlugin.getPlugin(Main.class);

        @Override
        public void onGuildMessageReceived(@Nonnull GuildMessageReceivedEvent e) {
            if(e.isWebhookMessage() || e.getAuthor().isBot() || e.getAuthor().isFake()) {
                System.out.println("zdar vole jak je");
                return;
            }
            String name = e.getAuthor().getName();
            String message = e.getMessage().getContentRaw();
            Bukkit.broadcastMessage(plugin.prefixDiscord + name + ": " + message);
        }
    }