From df6576ad10940f5e90851504190a5cae876eadcd Mon Sep 17 00:00:00 2001 From: Joel Date: Sun, 21 Feb 2021 22:44:17 +0100 Subject: [PATCH] Checking if bot is sending a dm to itself. --- .../java/zone/themcgamer/discordbot/events/GuildsListener.java | 1 - .../java/zone/themcgamer/discordbot/utilities/GuildUtils.java | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/discordbot/src/main/java/zone/themcgamer/discordbot/events/GuildsListener.java b/discordbot/src/main/java/zone/themcgamer/discordbot/events/GuildsListener.java index 38fa045..31f3978 100644 --- a/discordbot/src/main/java/zone/themcgamer/discordbot/events/GuildsListener.java +++ b/discordbot/src/main/java/zone/themcgamer/discordbot/events/GuildsListener.java @@ -7,7 +7,6 @@ import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent; import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent; -import net.dv8tion.jda.api.events.guild.member.GuildMemberUpdateEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import zone.themcgamer.discordbot.BotConstants; import zone.themcgamer.discordbot.MGZBot; diff --git a/discordbot/src/main/java/zone/themcgamer/discordbot/utilities/GuildUtils.java b/discordbot/src/main/java/zone/themcgamer/discordbot/utilities/GuildUtils.java index 8f028fd..22e3bc9 100644 --- a/discordbot/src/main/java/zone/themcgamer/discordbot/utilities/GuildUtils.java +++ b/discordbot/src/main/java/zone/themcgamer/discordbot/utilities/GuildUtils.java @@ -31,6 +31,9 @@ public class GuildUtils { guild.removeRoleFromMember(member.getIdLong(), role).queue(); else guild.addRoleToMember(member.getIdLong(), role).queue(); + if (member.getUser() == MGZBot.getInstance().getJda().getSelfUser()) + return; + member.getUser().openPrivateChannel().queue(privateChannel -> { privateChannel.sendMessage(EmbedUtils.successEmbed().setDescription("Succesfully toggled " + role.getName() + " " + (!member.getRoles().contains(role) ? "On" : "Off")).build()).queue(); }, error -> {