added correct handling for welcomeChannel variable mismatch.
This commit is contained in:
parent
ba34562917
commit
2cdfef9d8a
|
@ -5,6 +5,7 @@ import moe.oko.Kiafumi.util.EmbedUI;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.entities.Activity;
|
import net.dv8tion.jda.api.entities.Activity;
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
import net.dv8tion.jda.api.events.ReadyEvent;
|
import net.dv8tion.jda.api.events.ReadyEvent;
|
||||||
import net.dv8tion.jda.api.events.guild.GuildJoinEvent;
|
import net.dv8tion.jda.api.events.guild.GuildJoinEvent;
|
||||||
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
|
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
|
||||||
|
@ -120,9 +121,11 @@ public class MainListener extends ListenerAdapter {
|
||||||
if(server.isWelcomeEnabled()) {
|
if(server.isWelcomeEnabled()) {
|
||||||
info("User [" + event.getUser().getName() + ":" + event.getUser().getId() + "] joined guild [" + event.getGuild().getName() + ':' + event.getGuild().getId() + "].");
|
info("User [" + event.getUser().getName() + ":" + event.getUser().getId() + "] joined guild [" + event.getGuild().getName() + ':' + event.getGuild().getId() + "].");
|
||||||
// Fetch the welcome channel from settings.
|
// Fetch the welcome channel from settings.
|
||||||
var textChannel = event.getGuild().getTextChannelById(server.getWelcomeChannel());
|
TextChannel textChannel;
|
||||||
if(textChannel == null) {
|
try {
|
||||||
error("Failed to send welcome message to guild " + event.getGuild().getId() + " as the welcome channel was not found.");
|
textChannel = event.getGuild().getTextChannelById(server.getWelcomeChannel());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
error("Failed to send join message to guild " + event.getGuild().getId() + " as the welcome channel was not found.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var dTF = DateTimeFormatter.ofPattern("MM-dd-yyyy");
|
var dTF = DateTimeFormatter.ofPattern("MM-dd-yyyy");
|
||||||
|
@ -140,11 +143,13 @@ public class MainListener extends ListenerAdapter {
|
||||||
@Override
|
@Override
|
||||||
public void onGuildMemberRemove(@NotNull GuildMemberRemoveEvent event) {
|
public void onGuildMemberRemove(@NotNull GuildMemberRemoveEvent event) {
|
||||||
info("User [" + event.getUser().getName() + ":" + event.getUser().getId() + "] left guild [" + event.getGuild().getName() + ':' + event.getGuild().getId() + "].");
|
info("User [" + event.getUser().getName() + ":" + event.getUser().getId() + "] left guild [" + event.getGuild().getName() + ':' + event.getGuild().getId() + "].");
|
||||||
// Fetch the welcome channel from settings.
|
|
||||||
var server = Kiafumi.instance.getServerManager().getOrCreateServer(event.getGuild());
|
var server = Kiafumi.instance.getServerManager().getOrCreateServer(event.getGuild());
|
||||||
if(server.isWelcomeEnabled()) {
|
if(server.isWelcomeEnabled()) {
|
||||||
var textChannel = event.getGuild().getTextChannelById(server.getWelcomeChannel());
|
// Fetch the welcome channel from settings.
|
||||||
if(textChannel == null) {
|
TextChannel textChannel;
|
||||||
|
try {
|
||||||
|
textChannel = event.getGuild().getTextChannelById(server.getWelcomeChannel());
|
||||||
|
} catch (Exception ex) {
|
||||||
error("Failed to send leave message to guild " + event.getGuild().getId() + " as the welcome channel was not found.");
|
error("Failed to send leave message to guild " + event.getGuild().getId() + " as the welcome channel was not found.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue