代表文字聊天频道。包含 TextSources 作为子级。
要向 TextChannel 发送聊天消息,请从 TextChannel:SendAsync() 拨打 LocalScript 。用户的相应 必须在那个频道中。
使用 ChannelTabsConfiguration 将不同文本通道的消息分开到聊天窗口的不同选项卡中
了解更多信息,请参阅体验内文字聊天。
概要
属性
TextChannel 只会向用户发送消息,可以直接向DirectChatRequester发送消息。
方法
向用户显示系统消息。
将 DirectChatRequester 设置为 TextChannel 。 TextChannel 只会向 DirectChatRequester 发送消息的用户发送消息。
添加一个 TextSource 到 TextChannel 指定用户ID的 Player 。
向服务器发送 TextChatMessage 。
活动
当在客户端上调用 TextChannel:DisplaySystemMessage() 时,或当客户端从服务器收到有效的 TextChannel:SendAsync() 响应时,发生火灾。
回调
当 TextChannel 收到来自外部的消信息时调用。
当 TextChannel 收到来自客户端的消息时,调用每个客户端来确定是否应该将该消息发送给该客户端。
属性
DirectChatRequester
TextChannel 只会向用户发送消息,可以直接向DirectChatRequester发送消息。此属性只能使用SetDirectChatRequester()来设置。
方法
DisplaySystemMessage
向用户显示系统消息。只能在 LocalScript 中使用,或在 Script 中使用 RunContext 的 Enum.RunContext.Client 。消息只对该用户可见,不会自动过滤或本地化。
参数
系统消息发送到 TextChannel .
用于识别系统消息类型,例如默认系统消息。
返回
一个具有 TextChatMessage 属性的 TextChatMessage.Status 与指示消信息状态的物品。
SetDirectChatRequester
将 DirectChatRequester 设置为 TextChannel . 此方法仅限于服务器脚本使用。
如果您正在使用 TextChatService 并拥有外部默认文本通道的自定义实现的直接聊天,请使用此 API。
当调用到一个 TextChannel 它是父辈于 TextChatService 并且没有现有的 TextSources 时,SetDirectChatRequester 将请求用户添加为 TextSource 并设置 DirectChatRequester 属性为通频道。
当 DirectChatRequester 设置时,只有能够与 DirectChatRequester 直接聊天的用户之间的消息才会被传送。
local function createWhisperChannel(fromPlayer, toPlayer)
local whisperChannel = Instance.new("TextChannel")
whisperChannel:SetDirectChatRequester(fromPlayer)
whisperChannel:AddUserAsync(toPlayer.UserId)
-- TextChannel 实例现在有两个 TextSource 实例。
return whisperChannel
end
参数
返回
AddUserAsync
添加 TextSource 到用户给定的 TextChannel 用户ID(带 Player.UserId),只能在 Script 中使用。
如果代表用户的 TextSource 不存在,这将添加一个 TextSource 。
如果用户代表的 TextSource 存在,这将返回 TextSource。
如果用户关闭聊天或不在服务器上,这将返回一个 tuple nil , false .
参数
返回
返回 和 如果为用户创建了新的 ,返回 和 如果存在现有的 或 如果用户关闭聊天或不在此服务器上。
SendAsync
向服务器发送 TextChatMessage 。只能在 LocalScript 中使用,或在 Script 中使用 RunContext 的 Enum.RunContext.Client 。
参数
要发送到 TextChannel 的消息。
用于附加到消信息的自定义元数据。
返回
一个具有 TextChatMessage 属性的 TextChatMessage.Status 与指示消信息状态的物品。
活动
MessageReceived
像 TextChatService.MessageReceived 一样,在客户端调用 TextChannel:DisplaySystemMessage() 时或从服务器收到有效的 TextChannel:SendAsync() 响应时发生。该事件仅在客户端发射。
如果服务器的 TextChannel.ShouldDeliverCallback 属性已绑定并返回 false , 客户端不会发射 TextChannel.MessageReceived .
使用 TextChatMessage 参数获取消息的 TextSource 和文本 (带 TextChatMessage.Text )。
TextChatMessage 参数是任何绑定到 TextChatService.OnIncomingMessage 或 TextChannel.OnIncomingMessage 的函数的最终结果。
参数
收到 TextChatMessage 。
回调
OnIncomingMessage
当 TextChannel 收到来自外部的消信息时调用。只能在客户端实现。
使用这个来装饰 TextChatMessages .如果此回调返回一个 TextChatMessageProperties ,那些属性将与 TextChatMessage 参数合并以创建一个新的 TextChatMessage 。
当与客户端发送消信息绑定时,此回调会两次运行;首先当消息初始发送并在本地接收时,然后当客户端从服务器接收过滤后的消息的结果时。
TextChannel.OnIncomingMessage 回调总是在 后 的 TextChatService.OnIncomingMessage 回调之后运行。
这应该仅在源验证码中定义一次 TextChannel 。多个绑定到同一通道的绑定将以非决定性方式覆盖 друг друга。
当 TextChatService:CreateDefaultTextChannels() 为真时,那些默认 TextChannels 将在内部分配其 TextChannel.OnIncomingMessage 回调以展示特殊默认行为。
参数
收到的 TextChatMessage 。
返回
如果返回了 TextChatMessageProperties,这些属性将与 TextChatMessage 参数合并,创建一个新的 TextChatMessage 具有这些属性。
ShouldDeliverCallback
当 TextChannel 收到来自客户端的消息时,调用每个客户端来确定是否应该将该消息发送给该客户端。只能在服务器上定义。
一旦定义,此回调需要返回真实值,例如 true 、 1 或 "hello" 来向该客户端发送消息。如果回调返回任何其他内容(包括 nil),那么该消息不会发送到该客户端,但发送者仍然会看到该消息。
发送者可以通过 TextChatMessage.TextSource 参考,而接收者是 textSource 参数。请注意,发送者和接收者可以相同,因为回调遍历所有可用接收器。在 Roblox Studio 中,你将在单独 播放 模式下成为唯一的发送者和接收者,消息。
参数
被发送的消息,其中还包含信息息发件人。
接收消信息的用户的 TextSource 。