代表文本聊天消息的不可变数据对象。
要了解如何使用 TextChatMessages,请参阅 体验内文本聊天。
概要
属性
TextChatMessage 的唯一标识符。
用于存储有关 TextChatMessage 的杂项数据的通用字段。
要添加到用户消息的前缀。
表示 TextChatMessage 的状态。
用户的过滤文本消息。
对原始 TextChannel 的引用。
对原始 TextSource 的引用。
消息最初发送的时间戳。
翻译和过滤后的文本消息。
属性
BubbleChatMessageProperties
ChatWindowMessageProperties
Metadata
用于存储有关 TextChatMessage 的杂项数据的通用字段。TextChannel:SendAsync() 和 TextChannel:DisplaySystemMessage() 的第二个参数用于填充此字段。
使用此字段在 TextChatService.OnIncomingMessage 和 TextChannel.OnIncomingMessage 回调中为特殊消息应用额外格式。
local TextChatService = game:GetService("TextChatService")
local generalChannel: TextChannel = TextChatService:WaitForChild("TextChannels").RBXGeneral
generalChannel:DisplaySystemMessage("这是一个错误!", "Game.Error.Generic")
generalChannel:DisplaySystemMessage("找不到保存数据!", "Game.Error.SaveDataNotFound")
generalChannel:DisplaySystemMessage("你赢得了游戏!", "Game.Info.Win")
generalChannel:DisplaySystemMessage("你输了游戏!", "Game.Info.Lose")
generalChannel.OnIncomingMessage = function(message: TextChatMessage)
if string.find(message.Metadata, "错误") then
local overrideProperties = Instance.new("TextChatMessageProperties")
overrideProperties.TextColor = Color3.fromRGB(255, 0, 0)
return overrideProperties
elseif string.find(message.Metadata, "信息") then
local overrideProperties = Instance.new("TextChatMessageProperties")
overrideProperties.TextColor = Color3.fromRGB(0, 255, 150)
return overrideProperties
end
return nil
end
以下是聊天系统发出的默认系统消息的参考:
元数据 | 描述 |
---|---|
Roblox.ChatTranslation.ChatWindow.SystemMessage | 表示系统可能会为玩家翻译聊天消息。 |
Roblox.Notification.Friend.Joined | 当玩家的连接之一加入体验时显示。 |
Roblox.MessageStatus.Warning.Floodchecked | 当玩家发送的消息被服务器限速时显示。 |
Roblox.MessageStatus.Warning.TextFilterFailed | 当玩家发送的消息因文本过滤问题无法显示时显示。 |
Roblox.MessageStatus.Warning.InvalidPrivacySettings | 当玩家的隐私设置阻止他们发送消息时显示。 |
Roblox.MessageStatus.Warning.MessageTooLong | 当玩家发送的消息内容过长时显示。 |
Roblox.MessageStatus.Warning.Unknown | 当系统因未知原因未能发送玩家的消息时显示。 |
Roblox.Help.Info | 显示来自 RBXHelpCommand TextChatCommand 的响应。 |
Roblox.Version.Info | 显示来自 RBXVersionCommand TextChatCommand 的响应。 |
Roblox.Team.Success.NowInTeam | 当玩家的团队变更时显示。 |
Roblox.Team.Error.CannotTeamChatIfNotInTeam | 当玩家在未加入 Team 时触发 RBXTeamCommand TextChatCommand 时显示。 |
Roblox.Whisper.Info.Success | 当玩家成功开始耳语对话时显示。 |
Roblox.Whisper.Welcome.Sent | 当进入耳语 TextChannel 时显示。 |
Roblox.Whisper.Error.CannotWhisperToSelf | 来自 RBXWhisperCommand TextChatCommand 的错误响应。 |
Roblox.Whisper.Error.TargetDoesNotExist | 来自 RBXWhisperCommand TextChatCommand 的错误响应。 |
Roblox.Whisper.Error.TooManyMatches | 来自 RBXWhisperCommand TextChatCommand 的错误响应。 |
Roblox.Whisper.Error.Unknown | 来自 RBXWhisperCommand TextChatCommand 的错误响应。 |
Roblox.Emote.Error.DoesNotExist | 来自 RBXEmoteCommand TextChatCommand 的错误响应。 |
Roblox.Emote.Error.UserEmotesNotEnabled | 来自 RBXEmoteCommand TextChatCommand 的错误响应。 |
Roblox.Emote.Error.TemporarilyUnavailable | 来自 RBXEmoteCommand TextChatCommand 的错误响应。 |
Roblox.Emote.Error.NotSupported | 来自 RBXEmoteCommand TextChatCommand 的错误响应。 |
Roblox.Emote.Error.SwitchToR15 | 来自 RBXEmoteCommand TextChatCommand 的错误响应。 |
Roblox.Emote.Error.AnimationPlaying | 来自 RBXEmoteCommand TextChatCommand 的错误响应。 |
Roblox.Mute.Error.PlayerNotFound | 来自 RBXMuteCommand TextChatCommand 的错误响应。 |
Roblox.Mute.Error.MultipleMatches | 来自 RBXMuteCommand TextChatCommand 的错误响应。 |
Roblox.Mute.Error.CannotMuteSelf | 来自 RBXMuteCommand TextChatCommand 的错误响应。 |
Roblox.Mute.Info.Success | 来自 RBXMuteCommand TextChatCommand 的成功响应。 |
Roblox.Unmute.Error.PlayerNotFound | 来自 RBXUnmuteCommand TextChatCommand 的错误响应。 |
Roblox.Unmute.Error.MultipleMatches | 来自 RBXUnmuteCommand TextChatCommand 的错误响应。 |
Roblox.Unmute.Error.CannotMuteSelf | 来自 RBXUnmuteCommand TextChatCommand 的错误响应。 |
Roblox.Unmute.Info.Success | 来自 RBXUnmuteCommand TextChatCommand 的成功响应。 |
PrefixText
要添加到用户消息的前缀。支持 Rich Text,因此开发人员可以为此文本设置自定义属性以支持聊天标签。
默认情况下,TextChatMessage.PrefixText 是 TextSource 的名称,它是通过 TextSource.UserId 与用户的 Player.DisplayName 关联的。