Skip to content

Commit

Permalink
Added handler for when the message is unavailable to fetch (eg. missi…
Browse files Browse the repository at this point in the history
…ng permissions).
  • Loading branch information
ygimenez committed Jun 7, 2024
1 parent 43e7b63 commit c418973
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/main/java/com/github/ygimenez/method/Pages.java
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,11 @@ public void acceptThrows(@NotNull User u, @NotNull PaginationEventWrapper wrappe
* @return The updated message instance.
*/
public static Message reloadMessage(@NotNull Message msg) {
return subGet(msg.getChannel().retrieveMessageById(msg.getId()), msg);
try {
return subGet(msg.getChannel().retrieveMessageById(msg.getId()), msg);
} catch (InsufficientPermissionException e) {
return msg;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
import net.dv8tion.jda.api.events.message.react.GenericMessageReactionEvent;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import net.dv8tion.jda.api.interactions.InteractionHook;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -86,7 +87,11 @@ public Message retrieveMessage() {
return message;
}

return Pages.subGet(channel.retrieveMessageById(message.getId()));
try {
return Pages.subGet(channel.retrieveMessageById(message.getId()));
} catch (InsufficientPermissionException e) {
return message;
}
}

/**
Expand Down

0 comments on commit c418973

Please sign in to comment.