Difference between revisions of "Bot Playground/Events/chat message"
From SmartBots Developers Docs
(Add note about speaker distance appearing NULL when only just appeared.) |
|||
(2 intermediate revisions by 2 users not shown) | |||
Line 12: | Line 12: | ||
{{API Variable|speaker_name}}The name of the sender | {{API Variable|speaker_name}}The name of the sender | ||
{{API Variable|speaker_uuid}}The UUID of the sender | {{API Variable|speaker_uuid}}The UUID of the sender | ||
− | {{API Variable|speaker_owner}}The UUID of the owner of the sender object | + | {{API Variable|speaker_owner}}The UUID of the owner of the sender object |
+ | {{API Variable|speaker_distance}}The distance to the sender in metres (works only for speaker_type of AGENT) | ||
+ | {{API Variable|speaker_x}}The x position in region of the sender (works only for speaker_type of AGENT) | ||
+ | {{API Variable|speaker_y}}The y position in region of the sender (works only for speaker_type of AGENT) | ||
+ | {{API Variable|speaker_z}}The z position in region of the sender (works only for speaker_type of AGENT) | ||
{{API Variable|message}}The text of the message | {{API Variable|message}}The text of the message | ||
{{API Variable|chat_type}}One of the following: Normal, Whisper, Shout, OwnerSay | {{API Variable|chat_type}}One of the following: Normal, Whisper, Shout, OwnerSay | ||
Line 24: | Line 28: | ||
Make sure to ignore bot's own messages (especially for auto-responders)! See the example below. | Make sure to ignore bot's own messages (especially for auto-responders)! See the example below. | ||
+ | |||
+ | == Speaker distance and coordinates == | ||
+ | |||
+ | This event also returns <code>speaker_distance</code>, <code>speaker_x</code>, <code>speaker_y</code>, <code>speaker_z</code> so that you can determine their position. It is important to note that these parameters may return NULL if the bot or speaking avatar has only just appeared in-world. | ||
== Example == | == Example == | ||
Line 35: | Line 43: | ||
}); | }); | ||
− | console.log("Bot is listening | + | console.log("Bot is listening for local chat"); |
</syntaxhighlight> | </syntaxhighlight> | ||
{{NavMenu}} | {{NavMenu}} |
Latest revision as of 14:14, 22 September 2025
Fires when bot receives a message in the local chat
Bot.on("chat_message", function(event) { ... });
Reference
This event comes with the following event object:
Variable | Required | Description | |
---|---|---|---|
event object properties: | |||
name | The name of the event | ||
speaker_type | The sender of the message. Can be AGENT or OBJECT | ||
speaker_name | The name of the sender | ||
speaker_uuid | The UUID of the sender | ||
speaker_owner | The UUID of the owner of the sender object | ||
speaker_distance | The distance to the sender in metres (works only for speaker_type of AGENT) | ||
speaker_x | The x position in region of the sender (works only for speaker_type of AGENT) | ||
speaker_y | The y position in region of the sender (works only for speaker_type of AGENT) | ||
speaker_z | The z position in region of the sender (works only for speaker_type of AGENT) | ||
message | The text of the message | ||
chat_type | One of the following: Normal, Whisper, Shout, OwnerSay | ||
own_message | If this message has been said by the bot itself |
Important note
Bot DOES hear what it says, so you will get a chat_message event when bot says something in local chat.
Make sure to ignore bot's own messages (especially for auto-responders)! See the example below.
Speaker distance and coordinates
This event also returns speaker_distance
, speaker_x
, speaker_y
, speaker_z
so that you can determine their position. It is important to note that these parameters may return NULL if the bot or speaking avatar has only just appeared in-world.
Example
Bot.on("chat_message", function(event) {
// Ignore own messages
if(event.own_message) { return; }
console.log(event.speaker_name + " says: \n" + event.message);
});
console.log("Bot is listening for local chat");