TextChatService

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

無法建立
服務

處理經驗內的文字聊天的服務,包括managing channels、裝飾訊息、過濾文字、creating commands、以及開發自訂聊天介面

要了解更多,請參閱 TextChatService 概觀

要進一步自訂,TextChatService 有以下單一兒童:

概要

屬性

方法

活動

回調

屬性

ChatTranslationEnabled

未複製
Roblox 指令碼安全性
平行讀取

決定是否啟用聊天翻譯。如果真實,系統訊息會通知玩家在他們第一次加入聊天時,聊天訊息可能會被翻譯成玩家的首選語言。

ChatVersion

Roblox 指令碼安全性
平行讀取

決定是否完全啟用 TextChatService 或返回到舊版聊天系統。將此屬性設為 Enum.ChatVersion.LegacyChatService 有效地禁用 TextChatService

CreateDefaultCommands

外掛程式安全性
平行讀取

決定是否 TextChatService 應創建預設 TextChatCommands

如果真實,下列 將被創建並放置在 名為 TextChatCommands 的內部 中:


<th>主要別名</th>
<th>次要別名</th>
<th>說明</th>
<th>使用示例</th>
</tr>
</thead>
<tbody>
<tr>
<td><b>RBX清除指令</b></td>
<td>清除</td>
<td>cls</td>
<td>清除本地使用者的聊天記錄。</td>
<td><code>/cls</code></td>
</tr>
<tr>
<td><b>RBXConsoleCommand</b></td> <td>控制台</td>
<td />
<td>開啟開發者控制台。</td> <td><code>/console</code> ></td>
</tr>
<tr>
<td><b>RBX表情指令</b></td>
<td>動作</td>
<td>e</td>
<td>播放虛擬人偶動作。</td>
<td><code>/e跳舞</code></td>
</tr>
<tr>
<td><b>RBX幫助指令</b></td>
<td>協助助</td>
<td>?</td>
<td>顯示聊天指令列表。</td>
<td><code>/幫助</code></td>
</tr>
<tr>
<td><b>RBXMute指令</b></td>
<td>靜音</td>
<td>m</td>
<td>使用 <code>Class.Player.Name|Name</code> 或 <code>Class.Player.DisplayName|DisplayName</code> 在所有 <code>Class.TextChannel|TextChannels</code> 中靜音用戶。</td>
<td><code>/m 用戶名</code></td>
</tr>
<tr>
<td><b>RBX團隊指令</b></td>
<td>團隊</td>
<td>t</td>
<td>進入團隊聊天模式,只有隊友可以看到訊息。</td>
<td><code>/t</code></td>
</tr>
<tr>
<td><b>RBXUnmute指令</b></td>
<td>取消静音</td>
<td>um</td>
<td>使用 <code>Class.Player.Name|Name</code> 或 <code>Class.Player.DisplayName|DisplayName</code> 在所有 <code>Class.TextChannel|TextChannels</code> 中取消用戶的静音。</td>
<td><code>/um 用戶名</code></td>
</tr>
<tr>
<td><b>RBX版本指令</b></td>
<td>版本</td>
<td>v</td>
<td>顯示聊天版本。</td>
<td><code>/版本</code></td>
</tr>
<tr>
<td><b>RBXWhisper指令</b></td>
<td>悄悄話</td>
<td>w</td>
<td>使用另一個 <code>Class.Player</code> 進入低語音模式。</td>
<td><code>/w DisplayName</code> 或 <code>/w @Username</code></td>
</tr>
</tbody>
名稱

請注意,即使 TextChatCommands 是真實的,您也可以編輯、建立、創作和移除 CreateDefaultCommands 。請注意,靜音和解除靜音指令適用於所有 TextChannels

CreateDefaultTextChannels

外掛程式安全性
平行讀取

決定是否 TextChatService 應創建預設 TextChannels 。如果真實,在運行時內的 Folder 命名為 文字通道TextChatService 將創建內部,以包含下表中說明的 TextChannels 。每個預設通道都有描述的特殊行為適用於使用內部綁定 TextChannel.OnIncomingMessage 回呼功能傳送通道的訊息,改變訊息在通過通頻道傳送時的外觀。回叫被自動分配到運行時 (如果 TextChannel 存在) 或當 TextChannel 創建時。


<th>說明</th>
</tr>
</thead>
<tbody>
<tr>
<td><b>RBX一般</b></td>
<td><code>類別.TextChannel</code> 對玩家訊息。在聊天窗口中,訊息修改為使 <code>Class.TextChatMessage.PrefixText|PrefixText</code> 獲得 <a href="/ui/rich-text">富文本字體色標</a> 以提供聊天玩家獨特名稱顏色。如果 <code>Class.Player.Team</code> 存在,那 <code>Class.Team.TeamColor</code> 將被使用,而不是預設名稱顏色。</td>
</tr>
<tr>
<td><b>RBX系統</b></td>
<td><code>系統訊息的 Class.TextChannel</code> 。在聊天窗口中,訊息會被修改為 Class.TextChatMessage.Text 預設會獲得淺灰色標籤,或者 Class.TextChatMessage.Metadata 包含「錯誤」字詞時會獲得紅色標籤。</td>
</tr>
<tr>
<td><b>RBX團隊[磚色]</b></td>
<td><code>Class.TextChannel</code> 用於團隊特定玩家訊息,在 <code>Class.Team.TeamColor|TeamColor</code> 在服務中使用時創建,當 <code>Class.Teams</code> 內的任何 <code>Class.Team</code> 使用時。創建的通道名稱是 <b>RBX團隊</b> 隨後跟隨 <code>Class.Team.TeamColor|TeamColor</code> 名稱。例如, RBXTeamCrimson 是一個 Class.TextChannel 創建時有一支活躍的團隊,其 Class.Team.TeamColor|TeamColor 屬性是"Crimson" 數據類型。BrickColor 。在聊天窗口中,訊息被修改,使 Class.TextChatMessage.PrefixText|PrefixText 變得與 Class.Player.TeamColor|TeamColor 匹配,並附上 [團隊] 。團隊通道創建 Class.TextSource|TextSources 對所有非 Class.Player.Neutral|Neutral 玩家,使他們能夠使用團隊聊天。如果沒有帶有相關 <code>Class.Team.TeamColor|TeamColor</code> 的剩餘團隊,通道將被移除。</td>
</tr>
<tr>
<td><b>RBXWhisper:[使用者1]_[使用者2]</b></td>
<td><code>Class.TextChannel</code> 用於兩名玩家之間的低語消息,當一名玩家使用另一名玩家的 <code>/whisper</code> 命令時創建。例如 RBXWhisper:2276836_505306092 是對玩家 Class.TextChannel 的 Class.Player.UserId|UserIds 和 5053060922276836505306092 的 Class.TextChannel 。內部悄悄話通道有兩個 <code>Class.TextSource|TextSources</code> 與各自的 <code>Class.Player.UserId|UserIds</code> 相關。在聊天窗口中,訊息的顏色與在 <b>RBXGeneral</b> 和 <code>Class.TextChatMessage.PrefixText</code> 中的訊息相同。悄悄話通道會在玩家離開體驗時被移除。</td>
</tr>
</tbody>
通道

請注意,預設 TextChannel.OnIncomingMessage 回呼可以被覆蓋。請注意,即使 TextChannels 是真實的,您也可以編輯、創建立、創作和移除 CreateDefaultTextChannels

不同文字通道的訊息可以使用 ChannelTabsConfiguration 在聊天視窗中分開到不同標籤。

方法

DisplayBubble

()

在提供的部分或玩家角色上方顯示聊天泡泡,並發射指定在此方法中的參數的BubbleDisplayed。如果您在角色內指定一個部分,例如頭部,就可以顯示非玩家角色(NPC)的泡泡。

請注意,此方法只適用於在 LocalScript 使用,或在 Script 中使用 RunContextEnum.RunContext.Client

參數

partOrCharacter: Instance

泡泡要顯示上方的部分或角色。

預設值:""
message: string

聊天泡泡中顯示的文字。

預設值:""

返回

()

CanUserChatAsync

暫停

決定使用者是否有權在體驗中聊天。父母控制設定等因素可能會阻止使用者傳送訊息。如果使用者ID未在當前伺服器中,發生錯誤。請注意,此方法可以與所有現有玩家 UserIdsScript 中使用 RunContextEnum.RunContext.ServerEnum.RunContext.Legacy 。此方法也可以在 LocalScript 中使用,但只能使用本地玩家的 UserId

參數

userId: number
預設值:""

返回

CanUsersChatAsync

暫停

決定兩名使用者之間是否會收到消息。不相容的父級控制設定或被阻止的狀態可能會阻止用戶間傳送訊息 TextChannels 內部使用此結果來確定是否傳送訊息給用戶。請注意,此方法只適用於使用 ScriptRunContextEnum.RunContext.ServerEnum.RunContext.Legacy 中。

參數

userIdFrom: number
預設值:""
userIdTo: number
預設值:""

返回

CanUsersDirectChatAsync

暫停

決定使用者是否有權直接與其他使用者聊天在基於其家長控制設定的體驗中。當使用時:

  • 通訊線是由使用者啟動的(不是由開發者或遊戲啟動的)
  • 通訊的存取被關閉和限制了

直接聊天的例子是兩個使用者之間的囑咐通道。

您可以根據結果使用此方法來啟用體驗中的某些功能。

當創建一個直接聊天的 TextChannel 時,使用 TextChannel:SetDirectChatRequester() 來設置要求者ID,以便通道可以決定是否向用戶傳送消息。當 TextChannel.DirectChatRequester 不為零時,TextChannels 內部使用此結果來決定是否向使用者傳送訊息。


local whoCanDirectChat = TextChatService:CanUsersDirectChatAsync(requesterUserId, { userId1, userId2 })
if #whoCanDirectChat > 0 then
-- 要求者的用戶ID可以導向聊天與 iPad1、Island2 或兩者都
else
-- 請求者的用戶ID無法與 iPad1 或 iPad2 直接聊天
end

請注意,此方法只適用於 ScriptRunContextEnum.RunContext.ServerEnum.RunContext.Legacy 使用。

參數

requesterUserId: number

將啟動直接聊天請邀請的使用者。如果要求者的用戶ID不在當前伺服器中,此方法將發生錯誤。

預設值:""
userIds: Array

一個列表用戶,要求者UUID想與直接聊天的用戶。現有伺服器中未找到的用戶將被忽略。

預設值:""

返回

一個包含可以參與直接聊天請邀請的使用者名單。如果沒有使用者能夠直接與要求者聊天的 requesterUserId,結果是一個空陣列。

範例程式碼

This example checks if two users can chat, creates a new TextChannel, and adds them to it.

CanUsersDirectChatAsync

local TextChatService = game:GetService("TextChatService")
local directChatParticipants = TextChatService:CanUsersDirectChatAsync(userId1, { userId2 })
-- Check for eligible participants
if #directChatParticipants > 0 then
local directChannel = Instance.new("TextChannel")
directChannel.Parent = TextChatService
for _, participant in directChatParticipants do
directChannel:AddUserAsync(participant)
end
return directChannel
end
warn("Could not create TextChannel. Not enough eligible users.")
return nil

活動

BubbleDisplayed

TextChatService:DisplayBubble() 被呼叫時發生火災。

參數

partOrCharacter: Instance
textChatMessage: TextChatMessage

MessageReceived

TextChannel.MessageReceived 一樣,在客戶端呼叫 TextChannel:DisplaySystemMessage() 時或從服務伺服器收到有效的 TextChannel:SendAsync() 回應時發生。此事件只在客戶端發射。

如果伺服器的 TextChannel.ShouldDeliverCallback 屬性已綁定並返回 false ,客戶端將不會發射 TextChatService.MessageReceived

使用 TextChatMessage 參數來獲得 TextSource 和訊息的文字 (使用 TextChatMessage.Text )。

TextChatMessage 參數是任何綁定到 TextChatService.OnIncomingMessageTextChannel.OnIncomingMessage 的函數的最終結果。

參數

textChatMessage: TextChatMessage

收到的 TextChatMessage


SendingMessage

當收件客戶呼叫 TextChannel:SendAsync() 時,發生火災。使用此來允許暫時顯示空白訊息給用戶,等待服務器回應到 TextChannel:SendAsync()

參數

textChatMessage: TextChatMessage

回調

OnBubbleAdded

當泡泡聊天即將顯示時,會呼叫此方法。這只能在客戶端實現。

使用此來自訂個別泡泡聊天訊息。如果此回呼返回 BubbleChatMessageProperties,這些屬性將被應用到相關泡泡上,覆蓋 BubbleChatConfiguration 屬性。如果 UICornerUIGradientImageLabel 被父輩在 BubbleChatMessageProperties 下覆蓋,它們也會覆蓋在 BubbleChatConfiguration 中定義的對應對象。

如果聊天訊息由玩家發送,message.TextSource 將對應該玩家,而 adornee 將是 nil

如果聊天訊息透過 傳送, 將提供,而 將是 。

當綁定到發送訊息的客戶端時,此回呼會兩次運行:首先當訊息最初在本地傳送和接收時,然後當客戶端從伺服器接收過濾訊息的結果時再次運行。

參數

收到的 TextChatMessage

adornee: Instance

泡泡聊天訊息附於的部分或角色。


返回

如果返回 BubbleChatMessageProperties,其屬性將覆蓋 BubbleChatConfiguration 屬性。

OnChatWindowAdded

當新訊息即將顯示在聊天窗口時,會呼叫此方法。此方法只能在客戶端實裝。

使用此來自訂聊天窗口中出現的個別訊息。如果此回呼返回 ChatWindowMessageProperties,這些屬性將被應用到相關的訊息上,覆蓋 ChatWindowConfiguration 屬性。如果 UIGradientChatWindowMessageProperties 下是父級,它也會覆蓋在 TextColor3 中定義的 ChatWindowConfiguration 屬性。

當綁定到發送訊息的客戶端時,此回呼會兩次運行:首先當訊息最初在本地傳送和接收時,然後當客戶端從伺服器接收過濾訊息的結果時再次運行。

參數

收到的 TextChatMessage


返回

如果返回 ChatWindowMessageProperties,其屬性將覆蓋 ChatWindowConfiguration 屬性。

OnIncomingMessage

TextChatService 收到來自外部的訊息時,會呼叫。只能在客戶端上實裝。

使用此來裝飾 TextChatMessages 。如果此回呼返回 TextChatMessageProperties ,這些屬性將與 TextChatMessage 參數合併,創建新的 TextChatMessage

當綁定到發送訊息的客戶端時,此回呼會兩次運行;首先當訊息最初在本地傳送和接收時,再次當客戶端從伺服器接收過濾訊息的結果時。

請注意,此 TextChatService.OnIncomingMessage 回呼在任何 **** 回呼之前執行 TextChannel.OnIncomingMessage

這應該只在來源代碼中定義一次。多個綁定將以非決定性方式互相覆蓋。

參數

收到的 TextChatMessage


返回

如果返回 TextChatMessageProperties,這些屬性將與 TextChatMessage 參數合併,創建一個新的 TextChatMessage 擁有這些屬性,否則,如果 nil 被返回,則 TextChatMessage 不會被更改。