TextChannel
*此內容很快就會推出您所選的語言版本。
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.
To learn more, see In-Experience Text Chat.
概要
屬性
The TextChannel will only deliver messages to users that can send direct messages to the DirectChatRequester.
方法
Displays a system message to the user.
Sets the DirectChatRequester for the TextChannel. The TextChannel will only deliver messages to users that can send direct messages to the DirectChatRequester.
Adds a TextSource to the TextChannel given userId of a Player.
Sends a TextChatMessage to the server.
活動
Fires when TextChannel:DisplaySystemMessage() is invoked on the client, or when the client receives a valid TextChannel:SendAsync() response from the server.
回調
屬性
DirectChatRequester
The TextChannel will only deliver messages to users that can send direct messages to the DirectChatRequester. This property can only be set using SetDirectChatRequester().
方法
DisplaySystemMessage
Displays a system message to user. Can only be used in a LocalScript, or in a Script with RunContext of Enum.RunContext.Client. Messages are only visible to that user and aren't automatically filtered or localized.
參數
The system message sent to the TextChannel.
Use to identify system message types, such as the default system messages.
返回
A TextChatMessage with TextChatMessage.Status property that indicates the condition of the message.
SetDirectChatRequester
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.
local function createWhisperChannel(fromPlayer, toPlayer)
local whisperChannel = Instance.new("TextChannel")
whisperChannel:SetDirectChatRequester(fromPlayer)
whisperChannel:AddUserAsync(toPlayer.UserId)
-- The TextChannel instance now has two TextSource instances.
return whisperChannel
end
參數
返回
AddUserAsync
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 TextSource and true if a new TextSource is created for the user, TextSource and false if there is an existing TextSource, or nil and false if the user has chat off or is not in this server.
SendAsync
Sends a TextChatMessage to the server. Can only be used in a LocalScript, or in a Script with RunContext of Enum.RunContext.Client.
參數
The message to send to the TextChannel.
Custom metadata to attach to the message.
返回
A TextChatMessage with TextChatMessage.Status property that indicates the condition of the message.
活動
MessageReceived
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.
參數
The received TextChatMessage.