diff --git a/src/main/java/tk/sciwhiz12/concord/ChatBot.java b/src/main/java/tk/sciwhiz12/concord/ChatBot.java index b1f73480..14ca199d 100644 --- a/src/main/java/tk/sciwhiz12/concord/ChatBot.java +++ b/src/main/java/tk/sciwhiz12/concord/ChatBot.java @@ -120,13 +120,21 @@ boolean checkSatisfaction() { return false; } - if (channel.getType() != ChannelType.TEXT) { - Concord.LOGGER.error(BOT, "The channel with ID {} is not a TEXT channel, it was of type {}.", + if (channel.getType() != ChannelType.TEXT && channel.getType() != ChannelType.GUILD_PUBLIC_THREAD && + channel.getType() != ChannelType.GUILD_PRIVATE_THREAD) { + Concord.LOGGER.error(BOT, + "The channel with ID {} is not a TEXT channel or non-announcement thread, it was of type {}.", ConcordConfig.CHAT_CHANNEL_ID.get(), channel.getType()); return false; } // Guild and channel IDs are correct, now to check permissions + + // If the channel is a thread, also require thread message send permissions + if (channel.getType().isThread()) { + REQUIRED_PERMISSIONS.add(Permission.MESSAGE_SEND_IN_THREADS); + } + final Sets.SetView missingPermissions = Sets .difference(REQUIRED_PERMISSIONS, guild.getSelfMember().getPermissions(channel)); diff --git a/src/main/java/tk/sciwhiz12/concord/command/ReportCommand.java b/src/main/java/tk/sciwhiz12/concord/command/ReportCommand.java index 23265524..572508e1 100644 --- a/src/main/java/tk/sciwhiz12/concord/command/ReportCommand.java +++ b/src/main/java/tk/sciwhiz12/concord/command/ReportCommand.java @@ -27,7 +27,9 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.channel.ChannelType; +import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.arguments.EntityArgument; import net.minecraft.core.BlockPos; @@ -79,10 +81,19 @@ private static int report(CommandContext ctx) throws Command final ChatBot bot = Concord.getBot(); final String channelID = ConcordConfig.REPORT_CHANNEL_ID.get(); - final TextChannel channel = channelID.isBlank() ? null : bot.getDiscord().getTextChannelById(channelID); + final GuildMessageChannel channel = channelID.isBlank() ? null : + bot.getDiscord().getChannelById(GuildMessageChannel.class, channelID); - // If reporting is disabled, also tell the user - if (channel == null) { + // Check permissions and channel type to see if sending is allowed + boolean sendingAllowed = false; + if (channel != null && (channel.getType() == ChannelType.TEXT || channel.getType() == ChannelType.GUILD_PUBLIC_THREAD || + channel.getType() == ChannelType.GUILD_PRIVATE_THREAD)) { + sendingAllowed = channel.canTalk() && channel.getGuild().getSelfMember() + .hasPermission(channel, Permission.MESSAGE_EMBED_LINKS); + } + + // If reporting is disabled or not possible, also tell the user + if (!sendingAllowed) { ctx.getSource().sendFailure( Translations.COMMAND_REPORT_STATUS.resolvedComponent(ctx.getSource(), Translations.COMMAND_STATUS_DISABLED.resolvedComponent(ctx.getSource()) diff --git a/src/main/java/tk/sciwhiz12/concord/msg/Messaging.java b/src/main/java/tk/sciwhiz12/concord/msg/Messaging.java index 2519d870..3cecd066 100644 --- a/src/main/java/tk/sciwhiz12/concord/msg/Messaging.java +++ b/src/main/java/tk/sciwhiz12/concord/msg/Messaging.java @@ -25,7 +25,7 @@ import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.*; -import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; import net.dv8tion.jda.api.entities.sticker.StickerItem; import net.minecraft.ChatFormatting; import net.minecraft.locale.Language; @@ -244,7 +244,8 @@ public static void sendToAllPlayers(MinecraftServer server, Member member, Messa } public static void sendToChannel(JDA discord, CharSequence text) { - final TextChannel channel = discord.getTextChannelById(ConcordConfig.CHAT_CHANNEL_ID.get()); + final GuildMessageChannel channel = discord.getChannelById(GuildMessageChannel.class, + ConcordConfig.CHAT_CHANNEL_ID.get()); if (channel != null) { Collection allowedMentions = Collections.emptySet(); if (ConcordConfig.ALLOW_MENTIONS.get()) {