TextChatService

顯示已棄用項目

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

無法建立
服務

處理體驗中的文字聊天,包括管理頻道、裝飾消息、過濾文本、創建命令和開發自訂聊天界面。

要了解更多內容,請參閱 體驗內容聊天

概要

屬性

方法

活動

回調

屬性

ChatTranslationEnabled

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

ChatVersion

無法存取安全性
平行讀取

決定是否要完全啟用 TextChatService 或恢復到傳統聊天系統。將此屬性設置為 Enum.ChatVersion.LegacyChatService 將有效地禁用 TextChatService

CreateDefaultCommands

外掛程式安全性
平行讀取

決定是否建立預設 TextChatService

如果是,TextChatCommands 會創建並放置在 Folder 內的 TextChatCommands ,名為 1>TextChatCommands1> 裡面的 4>TextChatService4> 裡。


<tbody>
<tr>
<td><b>RBXClearCommand</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>RBXEmoteCommand</b></td>
<td>動作</td>
<td>e</td>
<td>播放一個虛擬人偶動作。</td>
<td><code>/e跳舞</code></td>
</tr>
<tr>
<td><b>RBXHelpCommand</b></td>
<td>協助助</td>
<td>?</td>
<td>顯示聊天指令清單。</td>
<td><code>/幫助</code></td>
</tr>
<tr>
<td><b>RBXMuteCommand</b></td>
<td>靜音</td>
<td>分</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>RBXTeamCommand</b></td>
<td>團隊</td>
<td>t</td>
<td>進入團隊聊天模式,討論只對團隊成員可見。</td>
<td><code>/t</code></td>
</tr>
<tr>
<td><b>RBXUnmuteCommand</b></td>
<td>取消靜音</td>
<td>嗯</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>RBXVersionCommand</b></td>
<td>版本</td>
<td>v</td>
<td>顯示聊天版本。</td>
<td><code>/version</code></td>
</tr>
<tr>
<td><b>RBXWhisperCommand</b></td>
<td>悄悄話嗚</td>
<td>w</td>
<td>進入其他 <code>Class.Player</code> 的傾聽模式。</td>
<td><code>/w 顯示名稱</code> 或 <code>/w @Username</code></td>
</tr>
</tbody>
名稱主要別名次要名稱說明使用範例

注意,即使 TextChatCommands 是真的,你還是可以編輯、建立、創作和移除 CreateDefaultCommands。也注意,靜音和恢復靜音對於所有 TextChannels 適用。

CreateDefaultTextChannels

外掛程式安全性
平行讀取

決定


<tbody>
<tr>
<td><b>RBXGeneral</b></td>
<td><code>Class.TextChannel 為玩家訊息。 在聊天窗口中,訊息被修改為讓 <code>Class.TextChatMessage.PrefixText|PrefixText</code> 獲得一個 <a href="../../../ui/rich-text.md">rich text</a> 字體顏色標��,以給給玩家獨特的名稱顏色。 如果</code>0> Class.Player.Team 存在,那麼 </td>
</tr>
<tr>
<td><b>RBXSystem</b></td>
<td><code>Class.TextChannel</code> 對於系統訊息。 在聊天窗口中,訊息是以 <code>Class.TextChatMessage.Text</code> 的淺灰色標籤預設為,或者 red 標籤,如果 <code>Class.TextChatMessage.Metadata</code> 包含 0>“錯誤”0> 字元。</td>
</tr>
<tr>
<td><b>RBXTeam\[BrickColor]</b></td>
<td> Class.TextChannel 為團隊專用玩家訊息,創造於使用任何 <code>Class.Team</code> 服務的 <code>Class.TextSource|TextSource</code> 與 0>Neutral0> 玩家,讓 3>Class.Team3> 與 <code>6>Neutral</code>6> 玩家無法使用。</td>
</tr>
<tr>
<td><b>RBXWhisper:\[userId1]\_\[userId2]</b></td>
<td><code>Class.TextChannel</code> 用於兩個玩家之間的哂臉訊息,創建時會在玩家使用 /</td>
</tr>
</tbody>
頻道說明

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

不同的文字頻道訊息可以在聊天窗口使用 ChannelTabsConfiguration 分別在不同的標籤中。

方法

DisplayBubble

void

在提供的方塊或玩家角色上顯示聊天泡泡,並且在此方法中指定的參數下發射 BubbleDisplayed 事件。可以顯示非玩家角色 (NPC) 的泡泡,如果你在角色中指定了一個方塊,例如它的頭部。

注意:此方法只適用於 LocalScriptScript 中使用,或在 RunContext 裡的 1>Class.Script.RunContext1> 。

參數

partOrCharacter: Instance

上方泡泡的部分或角色。

message: string

顯示在聊天泡泡中的文字。


返回

void

CanUserChatAsync

暫停

參數

userId: number

返回

CanUsersChatAsync

暫停

參數

userIdFrom: number
userIdTo: number

返回

CanUsersDirectChatAsync

暫停

決定用戶是否有權在體驗中與其他用戶直接聊天,並且在其親子保護設定中設定。要使用時:

  • 通訊線是由用戶發起 (而不是開發人員或遊戲開發人員發起)
  • 通訊資訊的存取是關閉的,且受限

參數

requesterUserId: number
userIds: Array

返回

範例程式碼

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)。

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

參數

textChatMessage: TextChatMessage

收到的 TextChatMessage


SendingMessage

發射時發生,當發送客戶端呼叫 TextChannel:SendAsync() 時。使用此來允許使用者在等待服務器回應 TextChannel:SendAsync() 時顯示預置訊息。

參數


回調

OnBubbleAdded

泡泡聊天即將顯示時呼叫。這只能在客戶端實現。

使用此來自訂個別泡泡聊天訊息。如果此回潮發生了 BubbleChatMessageProperties ,那些屬性將適用於指定

如果聊天訊息是由玩家發送,message.TextSource 將相應於該玩家,adornee 將成為nil

如果聊天訊息發送通過 TextChatService:DisplayBubble()adornee 將是提供的, partOrCharacter 將是提供的, 1> nil1> 將是提供的。

參數

來自 TextChatMessage 的內容。

adornee: Instance

泡泡聊天訊息的方塊或角色。


返回

如果返回 TextChatMessage,這些屬性將適用於屬性,覆蓋 BubbleChatConfiguration 屬性。

OnChatWindowAdded

呼叫時會顯示在聊天視窗中的新訊息。這只能在客戶端實現。

使用此來自訂個別在聊天視窗顯示的訊息。如果此回潮回潮回潮回潮回潮回潮回潮回潮回潮回潮回潮回潮

參數

來自 TextChatMessage 的內容。


返回

如果返回 TextChatMessage,這些屬性將被應用到相關的訊息,並且覆蓋 ChatWindowConfiguration 屬性。

OnIncomingMessage

呼叫時,TextChatService 正在接收來自發件人的來訊息。只能在客戶端實現。

使用此來裝飾 TextChatMessages 。如果此回潮返回 TextChatMessageProperties ,那些屬性將與 TextChatMessage 參數結合以創建新的 1> Class.TextChatMessage1> 。

當綁定到客戶端發送訊息時,此回叫是處理本地訊息和從服務器傳回的結果,這是一個雙重的回叫;首先,訊息被初始傳送到本地,然後再次傳送到服務器,當客戶端收到過濾器訊息的結果。

注意,此 TextChatService.OnIncomingMessage 回歸頁在任何 Class.TextChannel.OnIncomingMessage 回歸頁之前執行。

這項定義應該在源代碼中定義一次。多個綁定將以非定量方式疊加。

參數

來自 TextChatMessage 的內容。


返回

如果返回 TextChatMessageProperties,那些屬性將與 TextChatMessage 參數合併,以創建新的 TextChatMessage 與這些屬性,否則,如果返回 1> nil1> ,則 4> Class.TextChatMessage4> 不會改變。