How to detect if a message is private

I’m trying to make a cross-server chatting system for my game, but I do not want private messages to go through. So, how can I detect if a message that was sent is private?

1 Like

I already tried this, but it only happens when someone private chats somebody else for the first time. After that, the “/w” thing does not show up in the message.

Sorry for bad response before, I have now discovered a way.

The new TextChatService, when you create a whisper it starts a new channel. Therefore if you ONLY listen to the global channel, then you will only receive non-private messages

1 Like

You can detect when new whisper is created using this code

chatChannels.ChildAdded:Connect(function(channel)
	if not string.match(channel.Name, "RBXWhisper") then
		return
	end
	channel.ShouldDeliverCallback = function(textChatMessage, targetTextSource)
		if textChatMessage == nil or targetTextSource == nil then
			return false
		end
		local player = Players:GetPlayerByUserId(textChatMessage.TextSource.UserId)
		if player == nil then
			return false
		end
		print("whisper sent by " .. tostring(player) .. ": " .. tostring(textChatMessage.Text))
		return true
	end
end)
1 Like