Skip to content

Chat

This page contains code snippets for sending chat messages and commands as the player to the server, and displaying fake messages to the player!

Sending a chat message as the player.

kotlin
fun sendMessage(string: String) {
    client.connection?.sendChat(string)
}

Sending a command as the player.

kotlin
// Here, the direct boolean indicates if the message should be directly sent to the server
// or if it should be sent to the command listeners from the mods first.
fun sendCommand(string: String, direct: Boolean = false) {
    val command = string.removePrefix("/") // Normalises the string to be without the /
    if (direct) {
        client.connection?.send(ServerboundChatCommandPacket(command))
        return
    }

    client.connection?.sendCommand(command)
}

Showing a fake message to the player.

WARNING

The method client.gui.chat.addMessage has been replaced by client.gui.chat.addClientSystemMessage in minecraft versions 26.1+

kotlin
fun showMessage(string: String) {
    client.gui.chat.addMessage(Component.literal(string))
}

fun showMessage(component: Component) {
    client.gui.chat.addMessage(component)
}

Not affiliated with Mojang, Microsoft, or Hypixel.