diff --git a/src/main/java/cc/fascinated/bat/features/welcomer/WelcomerListener.java b/src/main/java/cc/fascinated/bat/features/welcomer/WelcomerListener.java index b479891..e270847 100644 --- a/src/main/java/cc/fascinated/bat/features/welcomer/WelcomerListener.java +++ b/src/main/java/cc/fascinated/bat/features/welcomer/WelcomerListener.java @@ -27,6 +27,6 @@ public class WelcomerListener implements EventListener { } WelcomerProfile profile = guild.getWelcomerProfile(); - profile.sendWelcomeMessage(user); + profile.sendWelcomeMessage(guild, user); } } diff --git a/src/main/java/cc/fascinated/bat/features/welcomer/WelcomerProfile.java b/src/main/java/cc/fascinated/bat/features/welcomer/WelcomerProfile.java index bccc48b..cf08dfb 100644 --- a/src/main/java/cc/fascinated/bat/features/welcomer/WelcomerProfile.java +++ b/src/main/java/cc/fascinated/bat/features/welcomer/WelcomerProfile.java @@ -1,6 +1,7 @@ package cc.fascinated.bat.features.welcomer; import cc.fascinated.bat.common.Serializable; +import cc.fascinated.bat.model.BatGuild; import cc.fascinated.bat.model.BatUser; import cc.fascinated.bat.service.DiscordService; import com.google.gson.Gson; @@ -72,9 +73,10 @@ public class WelcomerProfile extends Serializable { /** * Sends the welcome message to the user * + * @param guild The guild to send the message in * @param user The user to send the message to */ - public void sendWelcomeMessage(BatUser user) { + public void sendWelcomeMessage(BatGuild guild, BatUser user) { if (this.channel == null || (!this.isMessage() && !this.isEmbed())) { return; } @@ -82,11 +84,11 @@ public class WelcomerProfile extends Serializable { if (welcomerEmbed.isPingBeforeSend()) { // Ping the user before sending the message this.channel.sendMessage(user.getDiscordUser().getAsMention()).queue(); } - this.channel.sendMessageEmbeds(welcomerEmbed.buildEmbed(user).build()).queue(); + this.channel.sendMessageEmbeds(welcomerEmbed.buildEmbed(guild, user).build()).queue(); return; } if (welcomerMessage != null) { - this.channel.sendMessage(welcomerMessage.buildMessage(user)).queue(); + this.channel.sendMessage(welcomerMessage.buildMessage(guild, user)).queue(); } } diff --git a/src/main/java/cc/fascinated/bat/features/welcomer/command/ChannelSubCommand.java b/src/main/java/cc/fascinated/bat/features/welcomer/command/ChannelSubCommand.java index d065a34..b91140e 100644 --- a/src/main/java/cc/fascinated/bat/features/welcomer/command/ChannelSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/welcomer/command/ChannelSubCommand.java @@ -8,7 +8,10 @@ import cc.fascinated.bat.model.BatGuild; import cc.fascinated.bat.model.BatUser; import lombok.NonNull; import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; +import net.dv8tion.jda.api.interactions.commands.OptionMapping; +import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; import org.springframework.stereotype.Component; @@ -18,13 +21,21 @@ import org.springframework.stereotype.Component; @Component("welcomer:channel.sub") @CommandInfo(name = "channel", description = "Set the welcomer channel") public class ChannelSubCommand extends BatSubCommand { + public ChannelSubCommand() { + super.addOption(OptionType.CHANNEL, "channel", "The channel to send the welcomer messages to", true); + } + @Override public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) { WelcomerProfile profile = guild.getWelcomerProfile(); - profile.setChannel(guild.getDiscordGuild().getTextChannelById(channel.getId())); - + OptionMapping channelOption = event.getOption("channel"); + if (channelOption == null) { + return; + } + TextChannel textChannel = channelOption.getAsChannel().asTextChannel(); + profile.setChannel(textChannel); event.replyEmbeds(EmbedUtils.successEmbed() - .setDescription("The welcomer channel has been set to %s".formatted(channel.getAsMention())) + .setDescription("The welcomer channel has been set to %s".formatted(textChannel.getAsMention())) .build()).queue(); } }