Remove linked role if user isn't linked in the db anymore
This commit is contained in:
parent
29d0757279
commit
bc8a8b9141
|
|
@ -6,11 +6,14 @@ import com.alttd.proxydiscordlink.objects.DiscordLinkPlayer;
|
||||||
import com.alttd.proxydiscordlink.util.Utilities;
|
import com.alttd.proxydiscordlink.util.Utilities;
|
||||||
import net.dv8tion.jda.api.JDA;
|
import net.dv8tion.jda.api.JDA;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
import net.dv8tion.jda.api.entities.Role;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
|
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.Commands;
|
import net.dv8tion.jda.api.interactions.commands.build.Commands;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class CommandUnlink extends DiscordCommand {
|
public class CommandUnlink extends DiscordCommand {
|
||||||
private final CommandData commandData;
|
private final CommandData commandData;
|
||||||
public CommandUnlink(JDA jda) {
|
public CommandUnlink(JDA jda) {
|
||||||
|
|
@ -34,6 +37,14 @@ public class CommandUnlink extends DiscordCommand {
|
||||||
|
|
||||||
DiscordLinkPlayer discordLinkPlayer = DiscordLinkPlayer.getDiscordLinkPlayer(member.getIdLong());
|
DiscordLinkPlayer discordLinkPlayer = DiscordLinkPlayer.getDiscordLinkPlayer(member.getIdLong());
|
||||||
if (discordLinkPlayer == null) {
|
if (discordLinkPlayer == null) {
|
||||||
|
Optional<Role> linkedRole = member.getRoles().stream().filter(role -> role.getIdLong() == BotConfig.DISCORD.LINKED_ROLE_ID).findAny();
|
||||||
|
if (linkedRole.isPresent()) {
|
||||||
|
member.getGuild().removeRoleFromMember(member, linkedRole.get()).queue();
|
||||||
|
event.replyEmbeds(Utilities.genericSuccessEmbed("Success", "Your Discord and Minecraft accounts have been unlinked."))
|
||||||
|
.setEphemeral(true)
|
||||||
|
.queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
Utilities.commandErrAutoRem("Your accounts aren't linked", event);
|
Utilities.commandErrAutoRem("Your accounts aren't linked", event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user