RbxChatBot
Note: This module only worked on server.
Hello Roblox! Here is my new library! RbxChatBot!
With this module, you can easily create a bot in Roblox chat. Inspired by discord.js.
To implement this in your game, you can take this file
RobloxChatBot.rbxm (3.5 KB)
and drop it into the studio, and then simply require it like this
local RbxChatBot = require(game.ReplicatedStorage.RobloxChatBot)
or, if you want to use this module up-to-date. do not use .rbxm file, and simply require it like this.
local RobloxChatBot = require(7294504893)
when requiring module with id, it won’t work on the studio
and then you’re all set!
How to use
you might be asking this, let’s diving into it.
first thing first let’s require it
local RobloxChatBot = require(game.ReplicatedStorage.RobloxChatBot)
and then, let’s create a new client
local RobloxChatBot = require(game.ReplicatedStorage.RobloxChatBot)
local client = RobloxChatBot.new()
and then, let’s set the bot’s name, chat color, and chat tag
local RobloxChatBot = require(game.ReplicatedStorage.RobloxChatBot)
local client = RobloxChatBot.new()
client.Name = "Tutorial"
client.ChatColor = Color3.new(255, 0, 0)
client.ChatTag = {
TagText = "BOT",
TagColor = Color3.fromRGB(0, 255, 0)
}
you can change the ChatColor to whatever you like, and edit the ChatTag if you want.
next, we need to detect when the player is sending a message.
client:on("message", function(message)
end)
as you can see. I put function with message parameter. this function will trigger when player sending a message.
let’s see what player is sending
client:on("message", function(message)
if message.content == "/blah" then
end
end)
so, if the message’s content is “/blah” we will reply to it!
client:on("message", function(message)
if message.content == "/blah" then
client:send(message.author.Name.." just said weird command.")
end
end)
let’s send a private message!
client:on("message", function(message)
if message.content == "/blah" then
client:send(message.author.Name.." just said weird command.")
client:sendPrivateMessage("you just said weird command", message.author)
end
end)
sendPrivateMessage takes two parameters. The first one is the message, the second one is the player object.
message.author will be a player’s object.
and then. we need the bot to be logged in.
client:login()
and, your script should look like this.
local RobloxChatBot = require(game.ReplicatedStorage.RobloxChatBot)
local client = RobloxChatBot.new()
client.Name = "Tutorial"
client.ChatColor = Color3.new(255, 0, 0)
client.ChatTag = {
TagText = "BOT",
TagColor = Color3.fromRGB(0, 255, 0)
}
client:on("message", function(message)
if message.content == "/blah" then
client:send(message.author.Name.." just said weird command.")
client:sendPrivateMessage("you just said weird command", message.author)
end
end)
client:login()
to log out, simply use
client:logout()
Other feature
you could also detect friendJoin, by using the events called friendJoin.
this takes two parameters. The first one is an array full of the joined player’s friends, The second one is the player object who just joined.
client:on("friendJoin", function(friends, playerWhoJustJoined)
for i, v in pairs(friends) do
print(v.Name.." is a friend with "..playerWhoJustJoined.Name)
end
end)
There is also a method to create a channel. Only the player who is in that channel can see the message.
it takes 2 parameters.
- channelName (string)
- channelParticipant (table)
RbxChatBot:CreateChannel("ChannelNameHere" {put all the player object you want here})
client:sendMessageToChannel("YourMessageHere", "ChannelNameHere") -- the channel name part is case-sensitive
when the bot is logged out, they wouldn’t be able to send any message!
however, even though the bot is logged out. they are still able to detect events
Drop a like if you like it!
this is one of the screenshots when I tested it!