Skip to content

Commit 3bee3cb

Browse files
Merge pull request #382 from Java-Discord/dynxsty/better_message_retrieval
Improve Forum Message Retrieval
2 parents 830e5cf + c295c62 commit 3bee3cb

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/main/java/net/javadiscord/javabot/systems/help/HelpForumUpdater.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ public void execute() {
4646
}
4747

4848
private void checkForumPost(@NotNull ThreadChannel post, HelpConfig config) {
49-
post.retrieveMessageById(post.getLatestMessageId()).queue(latest -> {
49+
post.getHistory().retrievePast(1).queue(messages -> {
50+
if (messages.isEmpty()) {
51+
log.error("Could not find messages in forum thread {}", post.getId());
52+
return;
53+
}
54+
// Simply get the first one, as we only requested a singular message
55+
Message latest = messages.get(0);
5056
long minutesAgo = (Instant.now().getEpochSecond() - latest.getTimeCreated().toEpochSecond()) / 60;
5157
boolean isThankMessage = isThanksMessage(latest);
5258
if (minutesAgo > config.getInactivityTimeoutMinutes() || minutesAgo > config.getRemoveThanksTimeoutMinutes() && isThankMessage) {
@@ -59,7 +65,7 @@ private void checkForumPost(@NotNull ThreadChannel post, HelpConfig config) {
5965
post.getName(), post.getOwnerId(), minutesAgo);
6066
});
6167
}
62-
}, e -> log.error("Could not find message with id {}", post.getLatestMessageId()));
68+
}, e -> log.error("Could not find latest message in forum thread {}:", post.getId(), e));
6369
}
6470

6571
private boolean isThanksMessage(@NotNull Message m) {

0 commit comments

Comments
 (0)