Explaining it in the rudest way possible.
Import the S02PacketChat as @Aftery and @Plumer-Man said.
var S02PacketChat = Java.type("net.minecraft.network.play.server.S02PacketChat");
Check if the packet is S02PacketChat as @Larissa said, add this in module.on("packet", function(e) {
if (e.getPacket() instanceof S02PacketChat) {
In order to read the message, you need to add this variable in the same place.
var Message = e.getPacket().getChatComponent().getUnformattedText();
To check if the Message contains the string of your preference, you have to add this in the same place... again:
if (Message.toLowerCase().contains("string of your preference")) {
e.cancelEvent();
}
// change the "string of your preference" to what you want.