เรียนรู้
Engine Class
TextChatService
ไม่สามารถสร้าง
บริการ

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่


สรุป
วิธีการ
CanUsersChatAsync(userIdFrom: User,userIdTo: User):boolean
CanUsersDirectChatAsync(requesterUserId: User,userIds: {any}):{any}
DisplayBubble(partOrCharacter: Instance,message: string):()
GetChatGroupsAsync(players: Instances):{any}
เหตุการณ์
BubbleDisplayed(partOrCharacter: Instance,textChatMessage: TextChatMessage):RBXScriptSignal
สมาชิกที่ได้รับทอด

เอกสารอ้างอิงเกี่ยวกับ API
คุณสมบัติ
ChatTranslationEnabled
ไม่ซ้ำ
การรักษาความปลอดภัยของสคริปต์ Roblox
อ่านพร้อมๆ กัน
ความสามารถ: Chat
TextChatService.ChatTranslationEnabled:boolean

ChatVersion
เลิกใช้แล้ว

CreateDefaultCommands
การรักษาความปลอดภัยของปลั๊กอิน
อ่านพร้อมๆ กัน
ความสามารถ: Chat
TextChatService.CreateDefaultCommands:boolean

CreateDefaultTextChannels
การรักษาความปลอดภัยของปลั๊กอิน
อ่านพร้อมๆ กัน
ความสามารถ: Chat
TextChatService.CreateDefaultTextChannels:boolean

วิธีการ
CanUserChatAsync
ผลตอบแทน
ความสามารถ: Chat
TextChatService:CanUserChatAsync(userId:User):boolean
พารามิเตอร์
userId:User
ส่งค่ากลับ

CanUsersChatAsync
ผลตอบแทน
ความสามารถ: Chat
TextChatService:CanUsersChatAsync(
userIdFrom:User, userIdTo:User
พารามิเตอร์
userIdFrom:User
userIdTo:User
ส่งค่ากลับ

CanUsersDirectChatAsync
ผลตอบแทน
ความสามารถ: Chat
TextChatService:CanUsersDirectChatAsync(
requesterUserId:User, userIds:{any}
พารามิเตอร์
requesterUserId:User
userIds:{any}
ส่งค่ากลับ
ตัวอย่างโค้ด
CanUsersDirectChatAsync
local TextChatService = game:GetService("TextChatService")
local directChatParticipants = TextChatService:CanUsersDirectChatAsync(userId1, { userId2 })
-- ตรวจสอบผู้เข้าร่วมที่มีสิทธิ์
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("ไม่สามารถสร้าง TextChannel ได้ ผู้ใช้ที่มีสิทธิ์ไม่เพียงพอ.")
return nil

DisplayBubble
ความสามารถ: Chat
TextChatService:DisplayBubble(
partOrCharacter:Instance, message:string
):()
พารามิเตอร์
partOrCharacter:Instance
message:string
ส่งค่ากลับ
()

GetChatGroupsAsync
ผลตอบแทน
ความสามารถ: Chat
TextChatService:GetChatGroupsAsync(players:Instances):{any}
พารามิเตอร์
players:Instances
ส่งค่ากลับ
ตัวอย่างโค้ด
ย้ายผู้เล่นไปยังเซิร์ฟเวอร์แชทที่ดีที่สุด
-- สคริปต์เซิร์ฟเวอร์
local TextChatService = game:GetService("TextChatService")
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local TARGET_PLACE_ID = 1234567890 -- รหัสสถานที่จุดหมาย
--[[
สถานะเซิร์ฟเวอร์ทั่วจักรวาลที่ Stubbed.
ในทางปฏิบัติ ข้อมูลนี้สามารถจัดเก็บและอัปเดตโดยใช้ MemoryStore
หรือระบบเบื้องหลังอื่น ๆ。
รูปแบบตัวอย่าง:
ActiveServers = {
{
serverId = "abc",
accessCode = "reserved-server-code",
groupUserCounts = {
groupA = 12,
groupB = 5
}
},
{
serverId = "def",
accessCode = "reserved-server-code",
groupUserCounts = {
groupB = 8
}
}
}
]]
local ActiveServers = {}
local function teleportPlayerToBestServer(player)
local success, chatGroups = pcall(function()
return TextChatService:GetChatGroupsAsync({ player })
end)
if not success or not chatGroups then
warn("ไม่สามารถดึงกลุ่มแชทสำหรับผู้เล่นได้:", player.UserId)
return
end
-- รวบรวมกลุ่มแชททั้งหมดที่ผู้เล่นมีสิทธิ์เข้าได้
local playerGroupIds = {}
for _, group in ipairs(chatGroups) do
for _, groupId in ipairs(group) do
playerGroupIds[groupId] = true
end
end
local bestServer = nil
local bestUserCount = 0
-- เลือกเซิร์ฟเวอร์ที่มีจำนวนผู้ใช้ที่เข้ากันได้มากที่สุด
for _, server in ipairs(ActiveServers) do
local compatibleUserCount = 0
for groupId, userCount in pairs(server.groupUserCounts) do
if playerGroupIds[groupId] then
compatibleUserCount += userCount
end
end
if compatibleUserCount > bestUserCount then
bestUserCount = compatibleUserCount
bestServer = server
end
end
if not bestServer then
warn("ไม่พบเซิร์ฟเวอร์ที่เหมาะสมสำหรับผู้เล่น:", player.UserId)
return
end
local ok, err = pcall(function()
TeleportService:TeleportToPrivateServer(
TARGET_PLACE_ID,
bestServer.accessCode,
{ player }
)
end)
if not ok then
warn("การย้ายล้มเหลว:", err)
end
end
Players.PlayerAdded:Connect(teleportPlayerToBestServer)

เหตุการณ์
BubbleDisplayed
ความสามารถ: Chat
TextChatService.BubbleDisplayed(
partOrCharacter:Instance, textChatMessage:TextChatMessage
พารามิเตอร์
partOrCharacter:Instance
textChatMessage:TextChatMessage

MessageReceived
ความสามารถ: Chat
TextChatService.MessageReceived(textChatMessage:TextChatMessage):RBXScriptSignal
พารามิเตอร์
textChatMessage:TextChatMessage

SendingMessage
ความสามารถ: Chat
TextChatService.SendingMessage(textChatMessage:TextChatMessage):RBXScriptSignal
พารามิเตอร์
textChatMessage:TextChatMessage

Callbacks
OnBubbleAdded
ความสามารถ: Chat
TextChatService.OnBubbleAdded(
message:TextChatMessage, adornee:Instance
พารามิเตอร์
adornee:Instance
ส่งค่ากลับ

OnChatWindowAdded
ความสามารถ: Chat
TextChatService.OnChatWindowAdded(message:TextChatMessage):Tuple
พารามิเตอร์
ส่งค่ากลับ

OnIncomingMessage
ความสามารถ: Chat
TextChatService.OnIncomingMessage(message:TextChatMessage):Tuple
พารามิเตอร์
ส่งค่ากลับ

©2026 Roblox Corporation. Roblox, โลโก้ Roblox และ Powering Imagination เป็นส่วนหนึ่งของเครื่องหมายการค้าที่จดทะเบียน และไม่ได้จดทะเบียนของเราในสหรัฐฯ และประเทศอื่นๆ