How to make chat bot

im not familiar with chatservice at all or the new textchat service. I’d like to make a chat bot that will send a message into the chat so that all players can see said message, ive looked at some documentation but im still pretty confused on what to do or where to start. An explamation would really help!!! (im not really asking for code)

thank you for your time

2 Likes

Alright. Chatbots require input and output. If input is player chatting in built-in chat, then you need to use Player.Chatted event for this. Output however it not as simple. I think this thread should provide enough info on how to script a chatted message (in default Roblox chat).

1 Like

Its a bit unclear what you are looking for but what I am gathering is that you want to make a system message show in the chat of all players?

The way I do this is I make a RemoteEvent on the client that makes the message, and then run remote:FireAllClients("message here") and it shows for everyone.

2 Likes

If you want to create an actual speaker (an entity that typically represents a user but isn’t restricted to representing a user), you can use ChatService:AddSpeaker() (the one that’s replicated under ServerScriptService) to create a new speaker, controlled by the server like so:

local chatService = require(script.Parent:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))

task.wait(10)

local speaker = chatService:AddSpeaker('Chat bot')
speaker:JoinChannel('All')
speaker:SayMessage('Hey!', 'All')

image

Much like a player, you can also make this bot have tags like this:

speaker:SayMessage('Hey!', 'All', {
	-- here is where the extra data (like chat tags and chat colour) go
	Tags = {
		{
			-- you can also add multiple tags like so
			TagText = 'Bot';
			TagColor = Color3.new(1,1,0);
		};
		{
			TagText = 'Cool';
			TagColor = Color3.new(1,0,0);
		}
	};
	ChatColor = Color3.new(0.5,0.5,0.5);
	NameColor = Color3.new(1,0,1)
})

image
Or, you can assign extra data to the speaker like so:

speaker:SetExtraData('Tags', {
		{
			TagText = 'Bot';
			TagColor = Color3.new(1,1,0);
		};
		{
			TagText = 'Cool';
			TagColor = Color3.new(1,0,0);
		}
	}
)
speaker:SetExtraData('ChatColor', Color3.new(0.5,0.5,0.5))
speaker:SetExtraData('NameColor', Color3.new(1,0,1))

image

6 Likes

thank you! this really helped me alot!!

i have a few questions tho,

will the script automatically recodnize these and assign the data? can the chatcolors and textcolor variables be named anything?

will this script work on both client and server?

Those are table indexes, not variables.

No, server only.

1 Like

Should the script be in ServerScriptService?

I got just the code for this!

function cm.getRGB(color)
    -- A table that maps color names to RGB values
    local colors = {
        ["red"] = "rgb(255,0,0)",
        ["green"] = "rgb(0,255,0)",
        ["blue"] = "rgb(0,0,255)",
        ["yellow"] = "rgb(255,255,0)",
        ["orange"] = "rgb(255,165,0)",
        ["purple"] = "rgb(128,0,128)",
        ["pink"] = "rgb(255,192,203)",
        ["black"] = "rgb(0,0,0)",
        ["white"] = "rgb(255,255,255)",
        ["brown"] = "rgb(165,42,42)",
        ["gold"] = "rgb(255,215,0)",
        ["silver"] = "rgb(192,192,192)"
    }
    -- Return the RGB value of the color name or nil if not found
    return colors[color]
end
local NPC=Character
local Result="Hello world!"
local rgbcolor = cm.getRGB(favcolor)
        local TextChat=game:GetService("TextChatService")
        local chatgroup=TextChat.TextChannels.RBXSystem
        chatgroup:DisplaySystemMessage("<font color=\""..rgbcolor.."\">"..NPC.Humanoid.DisplayName..": </font> <font color=\"rgb(255,255,255)\">"..Result.."</font> ")

Used this for my chatbots. This perfectly simulates a chat message on the local level. I haven’t tested this with the server but I assume it will still work the same.