Skip to main content

on_player_message; how do I get to the message in Python AZNB?



  • Official comment
    Micah M
    Beacon of Knowledge

    The message parameter is the correct way to get the contents of a chat message and it is the only property in python notebooks that has the text of a chat message. The [Username] at the beginning is a side effect of how Minecraft puts the output text back in chat, but the actual value of the message parameter passed into the function is the text the user typed. The message parameter is a python string, not an object, which means it doesn't have any message.text or message.value property or anything like that.

    For example, in this code:

    def on_player_message(message, sender, receiver, message_type):
       if(message == "jump"):


    typing "jump" in chat will cause the code to run but changing the second line to if(message=="[username] jump") would not trigger the condition.

    If you are specifically trying to get the Python code to work with NPC command buttons with /say, we do pre-pend [NPC] to the text, so you would just need to add that to your condition, for example:

       if(message == "[NPC] jump"):
  • Moderator Beacon of Knowledge Super Star

    Thanks, @micah m
    I can work with that. At least it's good to know I'm using the best data I can get ;)
    Maybe I'll break the string after the space, or test with the full string, as you suggested.
    Thanks, as always!


Please sign in to leave a comment.