Can't send message by chat API but subscribeToEven received

I tried to send message to chat by using

let memberID: string[] = ["slv0vPtt5Jg9mESe8aKe97YWF5z1"];"GLOBAL_CHAT", memberID, MAP_ID, "teleport!");


        $case: "chat",
        chat: {
          chatRecipient: "GLOBAL_CHAT",
          contents: "teleport!",
          localPlayerIds: memberID,
          mapId: MAP_ID,

I think it should send “teleport!” to chat but it dosen’t.


game.subscribeToEvent("playerChats", (data, context) => {
  game.setTextStatus(data.playerChats.contents, "slv0vPtt5Jg9mESe8aKe97YWF5z1");

is working!

and I got

And I also want to know about the input “localPlayers” of, it is a string array.
I’m not sure what is this meaning, I think this input is mening who send the message,
because localPlayers is empty array and playerChats wasn’t triggered, is this correct?

There are so many question can anyone help me?

By the way
I didn’t try yet, if I want to Whisper to other player
I need to using enterWhisper and chat both, is this correct?

Try logging in a second avatar. I usually just open an incognito tab.

For some reason, the function will send a chat to global_chat, but not put any log of it into your own chat box. Meaning if you are trying to test some sort of chat-back interaction, and happen to be logged in on the avatar the API key is tied to, you will never see the chats.

Local players still confuses me, as it seems like it might be redundant with Nearby. I’ve really only focused on Global_chat while I’ve tried to get my coding going, as it has the least oddities.

Remember that Whisper is not a chat function, despite the name. Whisper is an ad hoc private space between two people, for voice and video.

Hope those things help!

Thank you so much

you totally solve my all question! :smiley: :smiley:

And I also know how to send private message to other player! Thank you

Hi there!

Just offering a bit of context for what the options are for the recipient field are, and how localPlayerIds works;

If chatRecipient is set to GLOBAL_CHAT, the message will be sent to all users, and localPlayerIds is ignored.
If chatRecipient is set to LOCAL_CHAT, the message will be sent to each user specified in localPlayerIds.
If chatRecipient is set to ROOM_CHAT, the message will be sent to each user inside a room (‘current room’). localPlayerIds is also ignored here.

Thank you @opalrose
But I have new question now.
If chatRecipient and localPlayers both meaning who will get message, then how can I set message sender by using API?

I’m trying to let player send message to bot by using private message, and bot can auto send message back to player.

The message sender will always be the account tied to the API. There are some oddities for this, especially if the api account hasn’t ever logged into the space, but there is no way to alter what account sends the chats.