Getting the ROBLOX chat filter into my chatbot

What’s up fellow developers/scripters! So I lately have been thinking of a cool idea, to make a chatbot that chats out things from user input. I’ve got the game done, but I do not want to publish it for the sole reason: when a user puts in a swear word into the chatbot, it does not tag the words, so a user can go and make the bot swear damaging my reputation from ROBLOX and possibly banning me for this. That explains why this topic is made. I do not know how to implement the ROBLOX chat filter into my chatbot to prevent it from saying swear words, and I’d be disappointed if after all the project is a no-go. I have tried searching on the Developer Hub. I did find a topic quite related to filtering of the chat, but I can’t seem to find out how to make this do anything but anything on my game. So that’s why I’m here.

Thanks for reading! :slightly_smiling_face:

This article should help:

1 Like

That is the article I found already! Could you please specify what part of it I could use?

https://developer.roblox.com/en-us/api-reference/function/Chat/FilterStringForBroadcast

1 Like

This part of the script is what actually filters text:

local TextService = game:GetService("TextService")
 
local function getTextObject(message, fromPlayerId)
	local textObject
	local success, errorMessage = pcall(function()
		textObject = TextService:FilterStringAsync(message, fromPlayerId)
	end)
	if success then
		return textObject
	end
	return false
end
 
local function getFilteredMessage(textObject, toPlayerId)
	local filteredMessage
	local success, errorMessage = pcall(function()
		filteredMessage = textObject:GetChatForUserAsync(toPlayerId)
	end)
	if success then
		return filteredMessage
	end
	return false
end

I’ve used this code a while ago for a messaging system I made. I basically pasted this in a server script and I did this:

local textToBeFiltered = "gimme ur robux"
local playerThatSent = game.Players.evilguy
local playerThatRecieves = game.Players.goodboi

local textObject = getTextObject(textToBeFiltered, playerThatSent.UserId)
local filteredResult = getFilteredMessage(textObject, playerThatRecieves.UserId)

-- filteredResult variable is now the filtered string version of the original message

I’ve read through this, I understand it. Thanks for helping me, it is appreciated.

1 Like

Alright! This looks good. Thanks for helping.

1 Like