Apprendre
Classe de moteur
TextChatService
Création impossible
Service

*Ce contenu est traduit en utilisant l'IA (Beta) et peut contenir des erreurs. Pour consulter cette page en anglais, clique ici.



Référence API
Propriétés
ChatTranslationEnabled
Non répliqué
Lecture parallèle
Capacités : Chat
TextChatService.ChatTranslationEnabled:boolean

ChatVersion
Déprécié

CreateDefaultCommands
Lecture parallèle
Capacités : Chat
TextChatService.CreateDefaultCommands:boolean

CreateDefaultTextChannels
Lecture parallèle
Capacités : Chat
TextChatService.CreateDefaultTextChannels:boolean

PlatformIntegratedChat
Sécurité des scripts Roblox
Lecture parallèle
Capacités : Chat
TextChatService.PlatformIntegratedChat:Enum.RolloutState

Méthodes
CanUserChatAsync
Rendement
Capacités : Chat
TextChatService:CanUserChatAsync(userId:User):boolean
Paramètres
userId:User
Retours

CanUsersChatAsync
Rendement
Capacités : Chat
TextChatService:CanUsersChatAsync(
userIdFrom:User, userIdTo:User
Paramètres
userIdFrom:User
userIdTo:User
Retours

CanUsersDirectChatAsync
Rendement
Capacités : Chat
TextChatService:CanUsersDirectChatAsync(
requesterUserId:User, userIds:{any}
Paramètres
requesterUserId:User
userIds:{any}
Retours
Échantillons de code
CanUsersDirectChatAsync
local TextChatService = game:GetService("TextChatService")
local directChatParticipants = TextChatService:CanUsersDirectChatAsync(userId1, { userId2 })
-- Vérifiez les participants éligibles
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("Impossible de créer TextChannel. Pas assez d'utilisateurs éligibles.")
return nil

DisplayBubble
Capacités : Chat
TextChatService:DisplayBubble(
partOrCharacter:Instance, message:string
):()
Paramètres
partOrCharacter:Instance
message:string
Retours
()

GetChatGroupsAsync
Rendement
Capacités : Chat
TextChatService:GetChatGroupsAsync(players:Instances):{any}
Paramètres
players:Instances
Retours
Échantillons de code
TéléporterJoueurAuMeilleurServeurDeChat
-- Script serveur
local TextChatService = game:GetService("TextChatService")
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local TARGET_PLACE_ID = 1234567890 -- ID du lieu de destination
--[[
État du serveur à l'échelle de l'univers.
En pratique, ces données pourraient être stockées et mises à jour à l'aide de MemoryStore
ou d'un autre système backend.
Exemple de structure :
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("Échec de la récupération des groupes de discussion pour le joueur :", player.UserId)
return
end
-- Collecter tous les IDs de groupe de discussion auxquels le joueur est éligible
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
-- Choisir le serveur avec le plus grand nombre d'utilisateurs compatibles
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("Aucun serveur approprié trouvé pour le joueur :", 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("Échec du téléport :", err)
end
end
Players.PlayerAdded:Connect(teleportPlayerToBestServer)
Obtenir les groupes de discussion de manière asynchrone
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("Échec de la récupération des groupes de discussion")
return
end
for _, group in ipairs(chatGroups) do
-- Chaque groupe contient des chaînes d'ID de groupe de discussion.
-- Les joueurs partageant un ID de groupe correspondant peuvent discuter entre eux.
for _, groupId in ipairs(group) do
print("ID du groupe de discussion:", groupId)
end
end

Événements
BubbleDisplayed
Capacités : Chat
TextChatService.BubbleDisplayed(
partOrCharacter:Instance, textChatMessage:TextChatMessage
Paramètres
partOrCharacter:Instance
textChatMessage:TextChatMessage

MessageReceived
Capacités : Chat
TextChatService.MessageReceived(textChatMessage:TextChatMessage):RBXScriptSignal
Paramètres
textChatMessage:TextChatMessage

SendingMessage
Capacités : Chat
TextChatService.SendingMessage(textChatMessage:TextChatMessage):RBXScriptSignal
Paramètres
textChatMessage:TextChatMessage

Rappels
OnBubbleAdded
Capacités : Chat
TextChatService.OnBubbleAdded(
message:TextChatMessage, adornee:Instance
Paramètres
adornee:Instance
Retours

OnChatWindowAdded
Capacités : Chat
TextChatService.OnChatWindowAdded(message:TextChatMessage):Tuple
Paramètres
Retours

OnIncomingMessage
Capacités : Chat
TextChatService.OnIncomingMessage(message:TextChatMessage):Tuple
Paramètres
Retours

©2026 Société Roblox. Roblox, le logo Roblox et Powering Imagination font partie de nos marques déposées aux États-Unis et dans d'autres pays.