Skip to content
This repository was archived by the owner on Jun 19, 2021. It is now read-only.

Commit 9613c4e

Browse files
committed
Fixed member is null
1 parent 7374aac commit 9613c4e

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/main/java/org/yatopiamc/bot/captcha/YatoCaptcha.java

+8-11
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,18 @@ public void onGuildMemberJoin(GuildMemberJoinEvent e) {
6161

6262
public void onPrivateMessageReceived(PrivateMessageReceivedEvent e) {
6363
if(codes.containsKey(e.getAuthor())) {
64-
Member m;
6564
try {
66-
m = helpChannel.getGuild().getMember(e.getAuthor());
65+
helpChannel.getGuild().retrieveMember(e.getAuthor()).queue(member -> {
66+
if(codes.get(e.getAuthor()).equals(e.getMessage().getContentRaw())) {
67+
helpChannel.getGuild().addRoleToMember(member, Objects.requireNonNull(helpChannel.getGuild().getRoleById("808517734577078302" /*ROLE TO GIVE*/))).queue();
68+
codes.remove(e.getAuthor());
69+
e.getAuthor().openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessage("Verification successful.\nWelcome to YatopiaMC.\nHave a nice day!")).queue();
70+
} else
71+
e.getAuthor().openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessage("Verification unsuccessful.\nPlease try again.").addFile(generateImage(e.getAuthor()), "yatocatpcha.png").onErrorFlatMap(throwable -> helpChannel.sendMessage("Hello " + e.getAuthor().getAsMention() + ", I need you to open your DMs so that I can send you a captcha."))).queue();
72+
});
6773
} catch (Exception e1) {
6874
e.getAuthor().openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessage("You left YatopiaMC, so there is no need to verify you.")).queue();
69-
return;
7075
}
71-
72-
if(codes.get(e.getAuthor()).equals(e.getMessage().getContentRaw())) {
73-
assert m != null;
74-
helpChannel.getGuild().addRoleToMember(m, Objects.requireNonNull(helpChannel.getGuild().getRoleById("808517734577078302" /*ROLE TO GIVE*/))).queue();
75-
codes.remove(e.getAuthor());
76-
e.getAuthor().openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessage("Verification successful.\nWelcome to YatopiaMC.\nHave a nice day!")).queue();
77-
} else
78-
e.getAuthor().openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessage("Verification unsuccessful.\nPlease try again.").addFile(generateImage(e.getAuthor()), "yatocatpcha.png").onErrorFlatMap(throwable -> helpChannel.sendMessage("Hello " + e.getAuthor().getAsMention() + ", I need you to open your DMs so that I can send you a captcha."))).queue();
7976
}
8077
}
8178

0 commit comments

Comments
 (0)