What is Okwo?
Okwo is a Roblox-Discord bot that allows you to connect your Discord guild with game! Currently we brought one feature to show it off!
Link to the completed project
Why is this efficient?
We base on our own features, so we are sure that they are safe. also we do not choose the exact commands or functionalities for you, so you can make them by yourself. We also donât base only on Discord.
Beginning
First thing, what we should do is configuring our guild and bot.
Inviting bot
To invite bot you should use this link. After that, bot will be added to our guild.
Configuring guild
What we should do after inviting is making a role for our bot, granting proper permissions (reading channels and sending messages for this tutorial) and generate our tokens - codes that will keep our game safe.
If you type =token 0
, you will be prompted to enter the token name and bot will PM your personal access token, that you will need to use when connecting with guild.
Note: Currently you have to be guild creator to run this command!
Bot's response
Configuring in-game connection
To configure in-game connection with bot services, you can use our module, which will always stay updated for botsâ possibilities. After requiring module, we need to auth so we should type:
local Okwo = require(2021571149) -- INITIALIZING OKWO
local Client = Okwo.init("Client", token)
Scripting cross-server chat
In this step we should begin in creating event that will allow us to communicate with client in order to send messages. We create RemoteEvent
then. Also we will get the service and table deep copy function to do filtering.
local token = "TOKEN"
local channelId = "CHANNEL ID HERE"
local interval = 1
-- SCRIPT
local Okwo = require(2021571149) -- INITIALIZING OKWO
local Client = Okwo.init("Client", token)
local Event = Instance.new("RemoteEvent", game.ReplicatedStorage)
Event.Name = "DiscordChat"
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local TextService = game:GetService("TextService")
Now we can do the bot commands. Letâs begin with binding just action, when player writes message - setCommandEvent
.
-
args
- table of all arguments. -
command
- command object name of the used command (=g (COMMAND)
), -
date
- timestamp, when command was sent
local token = "TOKEN"
local channelId = "CHANNEL ID HERE"
local interval = 1
-- SCRIPT
local Okwo = require(2021571149) -- INITIALIZING OKWO
local Client = Okwo.init("Client", token)
local Event = Instance.new("RemoteEvent", game.ReplicatedStorage)
Event.Name = "DiscordChat"
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local TextService = game:GetService("TextService")
if channelId ~= nil then
Client:setCommandEvent(interval, nil, function(args, command, date)
Client:sendShared("CHAT", command)
end, channelId)
end
setCommandEvent
lets us fetch every message, not only specific command ( =g *
instead of =g (SPECIFIC COMMAND)
- You can also set a custom prefix to the command using =commandprefix
so youâll be able to do !(SOME COMMAND)
).
sendShared
will let us communicate with other servers and send data to others. We will name the action CHAT
so it will be easier to recognize it. Letâs retreive it now. There are 4 arguments:
-
interval
- time between checks (it syncs with the commands), -
sharedName
- how we recognize the request (CHAT
in this case), -
data
- data sent viasendShared
local token = "TOKEN"
local channelId = "CHANNEL ID HERE"
local interval = 1
-- SCRIPT
local Okwo = require(2021571149) -- INITIALIZING OKWO
local Client = Okwo.init("Client", token)
local Event = Instance.new("RemoteEvent", game.ReplicatedStorage)
Event.Name = "DiscordChat"
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local TextService = game:GetService("TextService")
if channelId ~= nil then
Client:setCommandEvent(interval, nil, function(args, command, date)
Client:sendShared("CHAT", command)
end, channelId)
end
function DeepCopy(tab)
local newtab = {}
for i, v in pairs(tab) do
if type(i) == "table" then i = DeepCopy(i) end
if type(v) == "table" then v = DeepCopy(v) end
newtab[i] = v
end
return newtab
end
Client:setSharedEvent(interval, "CHAT", function(name, data)
if data.author.discriminator == "RBLX" and Players:FindFirstChild(data.author.username) then return end
for _, Player in pairs(Players:GetPlayers()) do
local newMessage = DeepCopy(data)
newMessage.author.username = TextService:FilterStringAsync(newMessage.author.username, Player.UserId):GetNonChatStringForBroadcastAsync()
newMessage.content = TextService:FilterStringAsync(newMessage.content, Player.UserId):GetNonChatStringForBroadcastAsync()
Event:FireClient(Player, newMessage)
end
end)
AddShared allows us to bind action, when server receives the Shared request. The message was Encoded into string from JSON, before so firstly we need to Decode it. After that we have function that will check is message sent from discord or game (BELOW IS PART, WHERE WE ADD SENDING FROM GAME (CROSS-SERVER)), if from game then if the sender is in server, we prevent duplicating message.
After doing that we copy the message for every player, filter discordâs name, message and send it then with our event.
Now letâs add Cross-Server chat. We should bind to the Chatted event then. Letâs do this.
local token = "TOKEN"
local channelId = "CHANNEL ID HERE"
local interval = 1
-- SCRIPT
local Okwo = require(2021571149) -- INITIALIZING OKWO
local Client = Okwo.init("Client", token)
local Event = Instance.new("RemoteEvent", game.ReplicatedStorage)
Event.Name = "DiscordChat"
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local TextService = game:GetService("TextService")
if channelId ~= nil then
Client:setCommandEvent(interval, nil, function(args, command, date)
Client:sendShared("CHAT", command)
end, channelId)
end
function DeepCopy(tab)
local newtab = {}
for i, v in pairs(tab) do
if type(i) == "table" then i = DeepCopy(i) end
if type(v) == "table" then v = DeepCopy(v) end
newtab[i] = v
end
return newtab
end
Client:setSharedEvent(interval, "CHAT", function(name, data)
if data.author.discriminator == "RBLX" and Players:FindFirstChild(data.author.username) then return end
for _, Player in pairs(Players:GetPlayers()) do
local newMessage = DeepCopy(data)
newMessage.author.username = TextService:FilterStringAsync(newMessage.author.username, Player.UserId):GetNonChatStringForBroadcastAsync()
newMessage.content = TextService:FilterStringAsync(newMessage.content, Player.UserId):GetNonChatStringForBroadcastAsync()
Event:FireClient(Player, newMessage)
end
end)
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(msg)
msg = TextService:FilterStringAsync(msg, Player.UserId):GetNonChatStringForBroadcastAsync()
local username = TextService:FilterStringAsync(Player.Name, Player.UserId):GetNonChatStringForBroadcastAsync()
Client:sendShared("CHAT", {author = {username = username, discriminator = "RBLX"}, member = {}, content = msg})
if channelId ~= nil then
Client:sendMessage(channelId, "**"..username.."**: "..msg)
end
end)
end)
After binding we need to filter both message and username (as outgoing resources). We can send the message to Discord, to make Discord community able to read in-game messages. Next step is obviously sending Shared request. We select the âCHATâ command then and send Encoded table containing our sender username, tag (I used RBLX
to let people know that person is in other server. You can change it or remove though) and message.
Last step - receiving events on Client Side
We need to listen for the event we have created and we will send the messages with :SetCore()
function.
local event = game.ReplicatedStorage:WaitForChild("DiscordChat")
event.OnClientEvent:Connect(function(message)
game.StarterGui:SetCore("ChatMakeSystemMessage", {
Text = "[" .. message.author.username .. "#" .. message.author.discriminator .. "]: "..message.content;
})
end)
PS: You can set the channelId
to nil to disable Discord functionality.
You can also join our community to stay updated!
- https://wiki.0q0.eu/ - Wiki
- https://0q0.eu/cl/discord - Community Discord
Join our Community Discord to also participate in early access program of the newest features - such as Roblox group management right now.
Cheers!
The place you are linked for, doesnât work and will not to prevent spam and leaking tokens! Please be also sure to check and prevent people for example from abusing @here
and @everyone
!