How to create a real time game discord bot?


I was recently scrolling through YouTube and while I was doing this I found a showcase vid of a Discord bot which allowed to do different things in-game from a Discord bot command in real time. I am not sure how you would though. I know like the basic idea of how the ban system works as an example but how would I make it so it would kick the user if they are in the game. I am generally confused on how I could create this (I use JavaScript/node.js by the way).

I was thinking it could be some type of sending a request to the Roblox server but how would you know where to send the request which I don’t get.

Link to vid:

On the same server you host the Discord bot (well, you could have it on another server, but the rule of thumb is to not do distributed systems if it isn’t needed), you can make a REST API accessible by your Roblox servers. Authenticate yourself with a secret password that only a server script would have access to. You can store secret keys like this, even for other services like analytics, inside DataStoreService, so if your scripts do get leaked, your keys aren’t leaked as well.

On the webserver, store some “orders” that relate to each player’s Roblox id. These “orders” would include kicking, adding points, etc. From Roblox, poll your webserver at a reasonable interval, reading this data and reacting to it. If one of the user ids is there, take action, and then send a message back to the server to indicate that this “order” has been carried out. You should have a unique identifier for each of these orders to be able to do this effectively. This can be done by generating GUIDs or through some other kind of entropy.

1 Like

So your basically saying have like a while true do loop as an example and ever so often send a request to the webserver and if a user is in the server who is banned then kick as an example?

Sure, here’s pseudocode:

local ServerAddress = "some ip"
local AuthenticationHeaders = {
	["TOKEN"] = "secret password"
while true do
		local commands = HttpService:JSONDecode(HttpService:RequestAsync({
			Url = ServerAddress .. "/readCommands",
			Method = "GET",
			Headers = AuthenticationHeaders

		local playerIds = {}
		for _, player in ipairs(Players:GetPlayers()) do
			playerIds[player.UserId] = player
		for _, command in ipairs(commands) do
			local player = playerIds[command.targetId]
			if not player then

			if command.commandType == "kickPlayer" then

				Url = ServerAddress .. "/commandCompleted?commandId=" .. command.commandId,
				Method = "POST",
				Headers = AuthenticationHeaders

The backend is for you to implement.

While that would work; the strategy you are describing is called “short polling” and is a fairly naive approach that’d have high latency and bandwidth usage. Instead, you can employ “long polling” which you send a request and the webserver keeps the connection open until data is ready, and then returns.

Say you were short polling at a 60 second interval, if you are extremely unlucky, it could take up to a minute for the command to run in your game. By contrast, long polling would immediately return and the subsequent request would be ready for more data.

I can’t speak to their efficacy, but there are some resources on this forum that already outline and implement this idea, that you can use as a starting point.

With corresponding npm packages: scalable-roblox-long-polling - npm

1 Like

You can’t send stuff directly to Roblox, but you can send stuff directly to somewhere that Roblox could read from.

I’m sorry to disappoint however, but Discord has blocked all connections from Roblox, and currently there has been no official word from Discord on if you’re allowed to use proxies to evade the block (I’d assume not, for hopefully obvious reasons)

Your post does not relate to my question at all. I was not asking at all if you can send it directly from Discord but I was asking how you could make something happen in a game server in real time.

Also Discord blocked webhooks due to people abusing them for purposes like logging which is against the Discord api terms of use; although this does not relate to this post at all.

Also someone who works for the Discord staff team has stated that proxies are ok to use as long as you make sure they follow the terms of use and also they are rate limited.