Class
TextChannel
Represents a text chat channel.
Represents a text chat channel. Contains TextSources as
descendants.
To send a chat message to the TextChannel, call
TextChannel:SendAsync() from a LocalScript. The corresponding
TextSource of the user with TextSource.CanSend = true must be in
that channel.
Messages from different TextChannels can be separated into different tabs in
the chat window using ChannelTabsConfiguration. Multiple channels with
the same name might cause unexpected behavior with the chat window, even if
the player isn't a member of the other channels.
To learn more, see In-Experience Text Chat.
Properties 1#
DirectChatRequesterPlayer | The TextChannel will only deliver messages to users that can send direct
messages to the DirectChatRequester.ReadSafeReadOnlyNotReplicated |
DirectChatRequester: Player#
ReadOnlyNotReplicatedReadSafe
The TextChannel will only deliver messages to users that can send direct
messages to the DirectChatRequester. This property can only be set using
SetDirectChatRequester().
Methods 4#
| AddUserAsync | Adds a TextSource to the TextChannel given userId of a
Player.Yields |
| DisplaySystemMessage | Displays a system message to the user. |
| SendAsync | Sends a TextChatMessage to the server.Yields |
| SetDirectChatRequester | Sets the DirectChatRequester for
the TextChannel. The TextChannel will only deliver messages to users
that can send direct messages to the DirectChatRequester. |
AddUserAsync(userId: User): Tuple#
Yields
Adds a TextSource to the TextChannel given userId of the
user (with Player.UserId). Can only be used in a Script.
If a TextSource representing the user does not exist, this adds a
TextSource.
If a TextSource representing the user does exist, this returns the
TextSource.
If the user has chat off or isn't in the server, this returns a tuple
nil, false.
Returns
Tuple— ReturnsTextSourceandtrueif a newTextSourceis created for the user,TextSourceandfalseif there is an existingTextSource, ornilandfalseif the user has chat off or is not in this server.
DisplaySystemMessage(systemMessage: string, metadata: string): TextChatMessage#
Displays a system message to user. Can only be used in a
LocalScript, or in a Script with
RunContext of RunContext.Client. Messages
are only visible to that user and aren't automatically filtered or
localized.
| Name | Type | Default | Description |
|---|---|---|---|
systemMessage | string | The system message sent to the TextChannel. | |
metadata | string | Use to identify system message types, such as the default system messages. |
Returns
TextChatMessage— ATextChatMessagewithTextChatMessage.Statusproperty that indicates the condition of the message.
SendAsync(message: string, metadata: string): TextChatMessage#
Yields
Sends a TextChatMessage to the server. Can only be used in a
LocalScript, or in a Script with
RunContext of RunContext.Client. Please
note that only messages typed and sent by the user will be delivered.
The metadata argument has a limit of 200 characters. If this is called
with a metadata argument that has more than 200 characters, the message
will not be sent to other users. Instead, the sender will receive a
TextChatMessage with the TextChatMessage.Metadata and
TextChatMessage.Text properties set to empty strings.
| Name | Type | Default | Description |
|---|---|---|---|
message | string | The message to send to the TextChannel. | |
metadata | string | Custom metadata to attach to the message. |
Returns
TextChatMessage— ATextChatMessagewithTextChatMessage.Statusproperty that indicates the condition of the message.
SetDirectChatRequester(requester: Player): ()#
Sets the DirectChatRequester for
the TextChannel. This method is only available for use in server
scripts.
Use this API if you are working with TextChatService and have a
custom implementation of direct chat outside of the default text channels.
When called on a TextChannel that is parented to TextChatService and
has no existing TextSources, SetDirectChatRequester adds the requested
users as a TextSource and set the DirectChatRequester property for the
channel.
When DirectChatRequester is set, only messages between users that can
direct chat with the DirectChatRequester are delivered.
| Name | Type | Default | Description |
|---|---|---|---|
requester | Player | The Player whose direct-message permissions gate the channel;
only users who can send direct messages to this player are delivered
messages on the channel. |
Returns
()
Events 1#
| MessageReceived | Fires when TextChannel:DisplaySystemMessage() is invoked on the
client, or when the client receives a valid
TextChannel:SendAsync() response from the server. |
MessageReceived(incomingMessage: TextChatMessage)#
Like TextChatService.MessageReceived, fires when
TextChannel:DisplaySystemMessage() is invoked on the client, or
when the client receives a valid TextChannel:SendAsync() response
from the server. This event is only fired on the client.
If the server's TextChannel.ShouldDeliverCallback property is
bound and returns false, the client will not fire
TextChannel.MessageReceived.
Use the TextChatMessage parameter to get the TextSource
and the text of the message (with TextChatMessage.Text).
The TextChatMessage parameter is the final result of any functions
bound to TextChatService.OnIncomingMessage or
TextChannel.OnIncomingMessage.
| Name | Type | Default | Description |
|---|---|---|---|
incomingMessage | TextChatMessage | The received TextChatMessage. |
Callbacks 2#
| OnIncomingMessage | Called when TextChannel is receiving an incoming message. |
| ShouldDeliverCallback | Called for each client when TextChannel is receiving an incoming
message to determine whether or not it should be delivered to that client. |
OnIncomingMessage(message: TextChatMessage): Tuple#
Called when TextChannel is receiving an incoming message. Can only
be implemented on the client.
Use this to decorate TextChatMessages. If this
callback returns a TextChatMessageProperties, those properties are
merged with the TextChatMessage parameter to create a new
TextChatMessage.
When bound to the client sending a message, this callback is run twice; first when the message is initially sent and received locally, and again when the client receives the result of the filtered message from the server.
TextChannel.OnIncomingMessage callbacks always run after the
TextChatService.OnIncomingMessage callback.
This should be defined only once per TextChannel in the source
code. Multiple bindings to the same channel will override one another in a
nondeterministic manner.
When TextChatService:CreateDefaultTextChannels() is true, those
default TextChannels have their
TextChannel.OnIncomingMessage callbacks assigned internally in
order to exhibit special default behavior.
| Name | Type | Default | Description |
|---|---|---|---|
message | TextChatMessage | The incoming TextChatMessage. |
Returns
Tuple— If aTextChatMessagePropertiesis returned, those properties are merged with theTextChatMessageparameter to create a newTextChatMessagewith those properties.
ShouldDeliverCallback(message: TextChatMessage, textSource: TextSource): Tuple#
Called for each client when TextChannel is receiving an incoming
message to determine whether or not it should be delivered to that client.
Can only be defined on the server.
Once defined, this callback needs to return a truthy value such as true,
1, or "hello" to deliver the message to said client. If the callback
returns anything else (including nil), the message won't be delivered to
that client, although the sender will see the message regardless.
The sender can be referenced by TextChatMessage.TextSource, while
the receiver is the textSource argument. Note that the sender and
receiver can be the same, as the callback iterates through all possible
receivers.
| Name | Type | Default | Description |
|---|---|---|---|
message | TextChatMessage | The message being sent, which also contains the sender of the message. | |
textSource | TextSource | The TextSource of the user who will be receiving the message. |
Returns
Tuple— A truthy value (such astrue,1, or a non-empty string) to deliver the message to the given client, or a falsy value (includingnil) to withhold it from that client.
Inherited members#
Inherited from Instance 58
Properties (10)
Archivable, archivable, Capabilities, IsInSandbox, Name, Parent, PredictionMode, RobloxLocked, Sandboxed, UniqueId
Methods (39)
AddTag, children, ClearAllChildren, Clone, clone, Destroy, destroy, FindFirstAncestor, FindFirstAncestorOfClass, FindFirstAncestorWhichIsA, FindFirstChild, findFirstChild, FindFirstChildOfClass, FindFirstChildWhichIsA, FindFirstDescendant, GetActor, GetAttribute, GetAttributeChangedSignal, GetAttributes, GetChildren, getChildren, GetDebugId, GetDescendants, GetFullName, GetStyled, GetStyledPropertyChangedSignal, GetTags, HasTag, IsAncestorOf, IsDescendantOf, isDescendantOf, IsPropertyModified, QueryDescendants, Remove, remove, RemoveTag, ResetPropertyToDefault, SetAttribute, WaitForChild