Skip to content

Commit

Permalink
use onGuildMemberUpdate to work with member caching
Browse files Browse the repository at this point in the history
  • Loading branch information
danthe1st committed Nov 23, 2024
1 parent 5150b92 commit 0431733
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.discordjug.javabot.util.StringUtils;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateNicknameEvent;
import net.dv8tion.jda.api.events.guild.member.GuildMemberUpdateEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

import java.io.IOException;
Expand Down Expand Up @@ -46,20 +46,19 @@ public PingableNameListener(NotificationService notificationService) {

@Override
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
checkNickname(event.getMember(), null);
checkNickname(event.getMember());
}

@Override
public void onGuildMemberUpdateNickname(GuildMemberUpdateNicknameEvent event) {
checkNickname(event.getMember(), event.getNewNickname());
public void onGuildMemberUpdate(GuildMemberUpdateEvent event) {
checkNickname(event.getMember());
}

/**
* Checks whether the given {@link Member}'s nickname should be changed.
* @param member The {@link Member} to check.
* @param nickname The {@link Member}'s new Nickname, null if that does not exist.
*/
private void checkNickname(Member member, String nickname) {
private void checkNickname(Member member) {
if (!isPingable(member.getEffectiveName()) && !canBypassCheck(member)) {
changeName(member);
}
Expand Down

0 comments on commit 0431733

Please sign in to comment.