Skip to content

Comments

fix: allow forwarded messages with media in media-only channels#1419

Open
VlaM5 wants to merge 4 commits intoTogether-Java:developfrom
VlaM5:fix/forward-media-to-media-channel
Open

fix: allow forwarded messages with media in media-only channels#1419
VlaM5 wants to merge 4 commits intoTogether-Java:developfrom
VlaM5:fix/forward-media-to-media-channel

Conversation

@VlaM5
Copy link

@VlaM5 VlaM5 commented Feb 23, 2026

Fixes #1243

Forwarded messages that contain media (attachments, embeds, or links)
were incorrectly deleted in media-only channels, because the bot only
checked the message itself, not its MessageSnapshots.

Changes:

  • Extended messageHasNoMediaAttached() to also check MessageSnapshot contents
  • Extracted hasMedia() helper method for reuse
  • Added tests for forwarded messages with and without media

@VlaM5 VlaM5 requested a review from a team as a code owner February 23, 2026 13:06
@CLAassistant
Copy link

CLAassistant commented Feb 23, 2026

CLA assistant check
All committers have signed the CLA.

@VlaM5 VlaM5 requested a review from Zabuzard February 23, 2026 16:13
Zabuzard
Zabuzard previously approved these changes Feb 24, 2026
@Zabuzard
Copy link
Member

Zabuzard commented Feb 24, 2026

nice stuff, thanks. just make the CI/CD happy and we can get it merged soon :)

@Zabuzard
Copy link
Member

poggers, all green 👍

Copy link
Contributor

@firasrg firasrg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @VlaM5 for the work and the thoughtful solution! Left some comments to help make the PR cleaner, Good luck

return message.getAttachments().isEmpty() && message.getEmbeds().isEmpty()
&& !message.getContentRaw().contains("http");
if (hasMedia(message.getAttachments(), message.getEmbeds(), message.getContentRaw())) {
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be nice to add a log.debug here, just before the return

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looked at logging patterns in the codebase — actions are logged where decisions are made, not inside helper methods. For example, AutoPruneHelperRoutine logs in pruneRoleIfFull() rather than isRoleFull().

Following the same principle, I'd place the debug log in onMessageReceived() rather than messageHasNoMediaAttached(), since the latter is just a predicate. Does that make sense?

* @param embeds the embeds of the message or snapshot
* @param content the raw text content of the message or snapshot
*/
private boolean hasMedia(List<Message.Attachment> attachments, List<MessageEmbed> embeds,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • There is no need for javadoc here, since the method is private;
  • I think this method should be marked static;
  • based on the use above of this method
hasMedia(message.getAttachments(), message.getEmbeds(), message.getContentRaw())

why not simply put one single argument hasMedia(message) ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(javadoc isnt needed but its also not bad to have)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't matter if a method is private, we still have to maintain it and documentation is always going to help.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private static boolean hasMedia makes sense indeed, but lets decide where to place debugging (see discussion above) and I'll address both in a single commit.

return message.getMessageSnapshots()
.stream()
.noneMatch(snapshot -> hasMedia(snapshot.getAttachments(), snapshot.getEmbeds(),
snapshot.getContentRaw()));
Copy link
Contributor

@firasrg firasrg Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you make hasMedia() has one argument rather than 3, then you can simplify this part to noneMatch(this::hasMedia)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

u cant because the method is shared across the two types Message and MessageSnapshot and bc JDA is JDA they dont share a common interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to forward messages with images to media channels

5 participants