diff --git a/Essentials/src/main/resources/messages.properties b/Essentials/src/main/resources/messages.properties index f37586d6dc3..97d6533faf1 100644 --- a/Essentials/src/main/resources/messages.properties +++ b/Essentials/src/main/resources/messages.properties @@ -276,6 +276,7 @@ discordErrorLoggerNoPerms=Discord console logger has been disabled due to insuff discordErrorNoGuild=Invalid or missing server ID\! Please follow the tutorial in the config in order to setup the plugin. discordErrorNoGuildSize=Your bot is not in any servers\! Please follow the tutorial in the config in order to setup the plugin. discordErrorNoPerms=Your bot cannot see or talk in any channel\! Please make sure your bot has read and write permissions in all channels you wish to use. +discordErrorInvalidPerms=Your bot was not set up with the required permissions\! Missing permissions are\: {0}. discordErrorNoPrimary=You did not define a primary channel or your defined primary channel is invalid. Falling back to the default channel\: \#{0}. discordErrorNoPrimaryPerms=Your bot cannot speak in your primary channel, \#{0}. Please make sure your bot has read and write permissions in all channels you wish to use. discordErrorNoToken=No token provided\! Please follow the tutorial in the config in order to setup the plugin. diff --git a/EssentialsDiscord/build.gradle b/EssentialsDiscord/build.gradle index 3fc6ee8064d..f21f32f6460 100644 --- a/EssentialsDiscord/build.gradle +++ b/EssentialsDiscord/build.gradle @@ -4,7 +4,7 @@ plugins { dependencies { compileOnly project(':EssentialsX') - implementation('net.dv8tion:JDA:5.3.0') { + implementation('net.dv8tion:JDA:5.6.1') { exclude(module: 'opus-java') } implementation 'com.github.MinnDevelopment:emoji-java:v6.1.0' diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/JDADiscordService.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/JDADiscordService.java index 96a8300a9a0..a248406e8c1 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/JDADiscordService.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/JDADiscordService.java @@ -8,8 +8,10 @@ import com.earth2me.essentials.utils.FormatUtil; import com.earth2me.essentials.utils.NumberUtil; import com.earth2me.essentials.utils.VersionUtil; +import com.google.common.collect.ImmutableList; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDABuilder; +import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.Webhook; @@ -191,6 +193,17 @@ public void startup() throws LoginException, InterruptedException { throw new IllegalArgumentException(tlLiteral("discordErrorNoGuild")); } + final Collection requiredPermissions = ImmutableList.of(Permission.MANAGE_WEBHOOKS, Permission.MANAGE_ROLES, Permission.NICKNAME_MANAGE, Permission.VIEW_CHANNEL, Permission.MESSAGE_SEND, Permission.MESSAGE_EMBED_LINKS); + final String[] missingPermissions = requiredPermissions.stream() + .filter(permission -> !guild.getSelfMember().hasPermission(permission)) + .map(Permission::getName) + .toArray(String[]::new); + + if (missingPermissions.length > 0) { + invalidStartup = true; + throw new IllegalArgumentException(tlLiteral("discordErrorInvalidPerms", String.join(", ", missingPermissions))); + } + interactionController = new InteractionControllerImpl(this); // Each will throw an exception if disabled try {