quick fix for start-up hang when the bot does not have the 'GUILD_MEMBERS' intent
This commit is contained in:
parent
df0f141c45
commit
9435d86106
|
@ -0,0 +1,124 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>uk.co.angrybee.joe</groupId>
|
||||
<artifactId>discord-whitelister</artifactId>
|
||||
<name>discord-whitelister</name>
|
||||
<version>1.3.8</version>
|
||||
<url>https://github.com/JoeShimell/DiscordWhitelisterSpigot</url>
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>2.5.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>2.8.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.7.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<relocations />
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>1.8</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>install</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<tasks>
|
||||
<copy />
|
||||
</tasks>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<id>bintray-dv8fromtheworld-maven</id>
|
||||
<name>bintray</name>
|
||||
<url>https://dl.bintray.com/dv8fromtheworld/maven</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.16.3-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
</project>
|
53
pom.xml
53
pom.xml
|
@ -6,15 +6,15 @@
|
|||
|
||||
<groupId>uk.co.angrybee.joe</groupId>
|
||||
<artifactId>discord-whitelister</artifactId>
|
||||
<version>1.3.6</version>
|
||||
<version>1.3.8</version>
|
||||
|
||||
<name>discord-whitelister</name>
|
||||
<url>https://github.com/JoeShimell/DiscordWhitelisterSpigot</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.7</maven.compiler.source>
|
||||
<maven.compiler.target>1.7</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
|
@ -34,22 +34,16 @@
|
|||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.14.2-R0.1-SNAPSHOT</version>
|
||||
<version>1.16.3-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.dv8tion</groupId>
|
||||
<artifactId>JDA</artifactId>
|
||||
<version>4.BETA.0_30</version>
|
||||
<version>4.2.0_211</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>club.minnced</groupId>
|
||||
|
@ -77,6 +71,12 @@
|
|||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>2.12.1</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-shade-plugin -->
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -133,10 +133,33 @@
|
|||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<finalName>uber-${project.artifactId}-${project.version}</finalName>
|
||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<relocations>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>1.8</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>install</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<tasks>
|
||||
<copy file="plugin.yml" tofile="${basedir}/plugin.yml"/>
|
||||
</tasks>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
</pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
@ -147,6 +170,12 @@
|
|||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package uk.co.angrybee.joe;
|
||||
|
||||
import net.dv8tion.jda.api.events.DisconnectEvent;
|
||||
import net.dv8tion.jda.api.events.ShutdownEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.dv8tion.jda.api.requests.CloseCode;
|
||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
// Check for privileged intents on disconnect
|
||||
public class CheckIntents extends ListenerAdapter
|
||||
{
|
||||
@Override
|
||||
public void onShutdown(ShutdownEvent shutdownEvent)
|
||||
{
|
||||
CheckIntents(shutdownEvent.getCloseCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnect(DisconnectEvent disconnectEvent)
|
||||
{
|
||||
CheckIntents(disconnectEvent.getCloseCode());
|
||||
}
|
||||
|
||||
private void CheckIntents(CloseCode closeCode)
|
||||
{
|
||||
if(closeCode == null)
|
||||
return;
|
||||
|
||||
if(closeCode == CloseCode.DISALLOWED_INTENTS)
|
||||
{
|
||||
DiscordClient.ShutdownClient();
|
||||
|
||||
DiscordWhitelister.getPluginLogger().severe("[DiscordWhitelister] Cannot connect as this bot is not eligible to request the privileged intent 'GUILD_MEMBERS'");
|
||||
DiscordWhitelister.getPluginLogger().severe("[DiscordWhitelister] To correct this please go to your bot located at: https://discord.com/developers/applications and enable 'Server Members Intent'");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,6 +8,8 @@ import net.dv8tion.jda.api.entities.*;
|
|||
import net.dv8tion.jda.api.events.guild.member.GuildMemberLeaveEvent;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||
import net.dv8tion.jda.internal.utils.PermissionUtil;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
@ -62,9 +64,19 @@ public class DiscordClient extends ListenerAdapter
|
|||
|
||||
try
|
||||
{
|
||||
javaDiscordAPI = new JDABuilder(AccountType.BOT).setToken(clientToken).addEventListeners(new DiscordClient()).build();
|
||||
//javaDiscordAPI = new JDABuilder(AccountType.BOT).setToken(clientToken).addEventListeners(new DiscordClient()).build();
|
||||
|
||||
javaDiscordAPI = JDABuilder
|
||||
.createDefault(clientToken)
|
||||
.addEventListeners(new DiscordClient())
|
||||
.addEventListeners(new CheckIntents())
|
||||
.enableIntents(GatewayIntent.GUILD_MEMBERS)
|
||||
.build();
|
||||
|
||||
javaDiscordAPI.awaitReady();
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (LoginException | InterruptedException e)
|
||||
|
|
|
@ -10,5 +10,5 @@ public class VersionInfo
|
|||
return "v." + getVersion();
|
||||
}
|
||||
|
||||
private static String version = "1.3.7";
|
||||
private static String version = "1.3.8";
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: DiscordWhitelister
|
||||
version: 1.3.7
|
||||
version: 1.3.8
|
||||
author: Joe Shimell
|
||||
main: uk.co.angrybee.joe.DiscordWhitelister
|
||||
description: Discord whitelister bot.
|
Loading…
Reference in New Issue