Text Chat Service
요약
속성
메서드
CanUserChatAsync(userId: User):boolean |
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 |
MessageReceived(textChatMessage: TextChatMessage):RBXScriptSignal |
SendingMessage(textChatMessage: TextChatMessage):RBXScriptSignal |
콜백
OnBubbleAdded(message: TextChatMessage,adornee: Instance):Tuple |
OnChatWindowAdded(message: TextChatMessage):Tuple |
OnIncomingMessage(message: TextChatMessage):Tuple |
상속된 멤버
API 참조
속성
Chat Version
메서드
Can Users Chat Async
Can Users Direct Chat Async
반환
코드 샘플
CanUsersDirectChatAsync
local TextChatService = game:GetService("TextChatService")
-- 두 사용자의 UserIds로 교체하세요
local userId1 = 1
local userId2 = 2
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 nilDisplay Bubble
Get Chat Groups Async
매개 변수
players:Instances |
반환
코드 샘플
최적 채팅 서버로 플레이어 전송
-- 서버 스크립트
local TextChatService = game:GetService("TextChatService")
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local TARGET_PLACE_ID = 1234567890 -- 목적지 장소 ID
--[[
전 세계 서버 상태의 스텁.
실제로 이 데이터는 MemoryStore
또는 다른 백엔드 시스템을 사용하여 저장하고 업데이트할 수 있습니다.
예시 형태:
ActiveServers = {
{
serverId = "abc",
privateServerId = game.PrivateServerId,
groupUserCounts = {
groupA = 12,
groupB = 5
}
},
{
serverId = "def",
privateServerId = game.PrivateServerId,
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
-- 플레이어가 자격이 있는 모든 채팅 그룹 ID 수집
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()
local teleportOptions = Instance.new("TeleportOptions")
teleportOptions.ReservedServerId = bestServer.privateServerId
TeleportService:TeleportAsync(
TARGET_PLACE_ID,
{ player },
teleportOptions
)
end)
if not ok then
warn("텔레포트 실패:", err)
end
end
Players.PlayerAdded:Connect(teleportPlayerToBestServer)채팅 그룹 비동기 가져오기
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local players = Players:GetPlayers()
local success, chatGroups = pcall(function()
return TextChatService:GetChatGroupsAsync(players)
end)
if not success then
warn("채팅 그룹을 가져오는 데 실패했습니다")
return
end
for _, group in ipairs(chatGroups) do
-- 각 그룹은 채팅 그룹 ID 문자열을 포함합니다.
-- 일치하는 그룹 ID를 공유하는 플레이어는 서로 채팅할 수 있습니다.
for _, groupId in ipairs(group) do
print("채팅 그룹 ID:", groupId)
end
end이벤트
Bubble Displayed
Text Chat Service. Bubble Displayed(
매개 변수
Message Received
매개 변수
Sending Message
매개 변수
콜백
On Bubble Added
매개 변수
반환
On Chat Window Added
On Incoming Message