Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

fix: TjBot tried to retrieve messages from channels it is not allowed in #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nonnull;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
Expand All @@ -25,7 +26,11 @@ public LastMessageInChannelListener(JDA jda) {
// Prime cache
jda.getGuilds()
.stream()
.flatMap(guild -> guild.getTextChannels().stream())
// Only return channels we are allowed to monitor (exclude moderator channels and so on)
.flatMap(guild -> guild.getTextChannels()
.stream()
.filter(chan -> guild.getSelfMember().hasPermission(chan, Permission.MESSAGE_HISTORY))
)
.forEach(it -> it.getIterableHistory().limit(1).queue(messages -> {
if (!messages.isEmpty()) {
Message message = messages.get(0);
Expand Down