DiscordSRV

DiscordSRV

86.8k Downloads

Add event to modify messages sent to Discord from Minecraft

Phoenix616 opened this issue ยท 6 comments

commented

Currently the only way to interact with the messages that get forwarded to the Discord is to log them with the DiscordGuildMessageSentEvent without any way of modifying it before it gets show in Discord. This can lead to issues with certain plugins that display non-Discord-compatible information like click/hover events or even have placeholders that are later replaced via packets directly as they will show up raw in the Discord message.

The easiest solution would be a new DiscordGuildForwardMessageEvent which is called before the message is forwarded with mutable information like the message text or the target channel as well as the sender's name or even completely cancelling the sending. (E.g. if you don't want the messages of members that haven't agreed to your/Discord ToS from leaking onto their service without explicit agreement)

EDIT: I just found out about the GameChatMessagePreProcessEvent which โ€’ while documented in a confusing/wrong way ("Called directly after a Discord message", not a Minecraft message?) โ€’ seems to be able to do that? Would be cool if someone could confirm that this is indeed the event that should be used for that (and maybe fix the docs to be more clear and add that to the example repo/api help pages)

commented

What you're looking for is DiscordGuildMessagePostProcessEvent, which is Discord -> Minecraft, where as GameChatMessage*ProcessEvent is Minecraft -> Discord. The event doesn't support hover or click events yet, see https://github.com/DiscordSRV/DiscordSRV/pull/766/files#diff-bd0594f57c210359c6927f5495c396f8c3d27f6c7df480a8ce0efdcbb200d35b

commented

I am indeed searching for Minecraft -> Discord so GameChatMessagePreProcessEvent is correct? If so the docs of that event should probably be updated.

commented

All events labeled as Pre and Post are editable with the exception of DiscordGuildMessagePostBroadcastEvent

commented

Yes, but the GameChatMessagePreProcessEvent states that it is for the Discord Message, not for the Minecraft message. The post event doesn't even have any documentation.

commented

Which is technically correct in that it is going to be a Discord message, going by the class name it is a GameChatMessage that is being processed, albeit it's quite poorly documented

commented

I've updated the docs on most of the events, they should be clearer as to what direction a message is going in now