Skip to content

Add message when discord bot is missing permissions #6228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Essentials/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion EssentialsDiscord/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -191,6 +193,17 @@ public void startup() throws LoginException, InterruptedException {
throw new IllegalArgumentException(tlLiteral("discordErrorNoGuild"));
}

final Collection<Permission> 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 {
Expand Down
Loading