How does Discord-To-Roblox work?

I want to make a discord bot myself that can do some stuff that affects roblox side. But more I research on it, More confused I get because majority of posts are for Roblox-To-Discord. But I want to achieve these;

  • Sending In-Game Announcements with command
  • Banning a person remotely using ban API
  • Giving a player badge
  • Editing a players datastore values

I would really appreciate some good explainations on how I can do these exactly
Note: I was thinking about using Messaging Service but Im not sure how I can even utilize that without risking some random getting access

1 Like

Open Cloud API, you are able to create API keys for your experiences and there is a bunch of types of API you can create.

2 Likes

Like @Lokispades said, there’s a whole bunch you can do with OpenCloud APIs.
Most of your examples can be achieved through the REST APIs, which involves HTTP requests.

For example:
You can access a data store entry with the API:

https://apis.roblox.com/cloud/v2/universe/UNIVERSE_ID/data-stores/SCOPE/DATA_STORE_NAME/ENTRY_KEY

(ignoring scope if it doesn’t exist).

From there, you can:

  • Send a PATCH request to update the entry
  • Send a DELETE request to delete the entry
  • Send a GET request to read the entry

all with the api key as a request header.


The same goes for the Ban API, which can be accessed by the endpoint:

https://apis.roblox.com/cloud/v2/universes/UNIVERSE_ID/user-restrictions/USER_ID

from there:

  • PATCH to update user restriction
  • GET to get the user restriction
  • DELETE to delete the user restriction

and so on. REST (REpresentational State Transfer) APIs is a standard across web servers, and by using different methods to endpoints you can achieve a lot. It’s actually quite simple compared to how it sounds.

Any questions, please ask!

Yeah, How could I get to send a global message through the bot? I didnt really get how Messaging Service works even after reading the documentry

well, you’ll want to first create a handler on the server.

MessagingService:SubscribeAsync("topic", function(data)
    local msgData = data.Data
    --etc.
end)

then, you can write code in your bot to broadcast to this topic. I’ll use JavaScript as it’s one of the languages you can code a Discord bot in.

You need to send a POST request to the URL with your API key and data. Make sure the API key has the correct permissions.

//example where hidden in environment
const {env} = require("process");
const apiKey = env.APIKey;

const topic = "topic name here";
const universeID = //

//then... (btw this needs to be in an async code block cuz we used await)
try {
    let response = await fetch(`https://apis.roblox.com/messaging-service/v1/universes/${universeId}/topics/${topic}`, {
        method: "POST", //we need to use the POST method
        headers: {
            "Content-Type": "application/json", //indicate JSON content in the request
            "x-api-key": apiKey //authentication method
        },
        body: JSON.stringify({
            message: "your message here"
        })
    });

    if (!response.ok) {
        throw new Error("could not send message. Status code: " + String(response.status);
    }
} catch(error) {
    console.log("Failed to send message. Error: " + error)
}

This should send the message to the game servers.

You can hook it up to discord events:

bot.on("messageCreate", async message => {
    let content = message.content;
    //etc.
});
1 Like


When I try to manually send an API request, it says “Failed to fetch”

yup, for some reason it doesn’t work that great in the developer console on browsers. If you have a JavaScript backend executor like Node.js, it should work just fine. I think it doesn’t work well on web consoles due to the domain it’s sending from.

If you’re using a different programming language such as Python, you can send the request through that too.

import requests
import json as JSON

try:
    requests.post(
        "https://apis.roblox.com/messaging-service/v1/universes/" + str(universeId) + "/topics/" + topic, 
        headers = {
            "content-type": "application/json",
            "x-api-key": "apiKey"
        },
        json = JSON.dumps({
            "message": "message here"
        })
    )
    #blah blah, checking code and stuff here
except Exception:
    print("failed to send request")

I still cant really make my bot work… I am currently using a 3rd Party Visual Bot Programmer (Because I lack skills in python :sob: ) And I cant get to send an API request to roblox for whatever reason

(assuming it’s in python)
you mean someone else is coding the bot? You should be able to use the requests library to send HTTP requests just fine, provided your API key is valid. Make sure it has the right permissions and try outputting the status code if it fails.

No I mean like those visual coding ones. Where you can use sketch-like coding style to make a bot. I can use luau good but I dont know much python so I use those

I’m not sure using those would be useful in the long term. Learning Python is pretty simple since you already know LuaU, so you can already think like a programmer.

Example:

import requests

url = "https://example.com"

r = requests.get(url,
headers = {"Key": "Value"})

print(r.text) # request response

There are a multitude of options you can use to learn Python. Even ChatGPT or any of those LLMs can be useful since Python is well documented, and the task you’re trying to achieve is relatively straightforward.

I do know how to read a python code but im not very good at writing :sob: … Is there any guides you know that’d be easy on a programmer?

Just some YouTube tutorials as a guide should work, once you’ve learnt one programming language it’s not so hard to learn more.

In my Python example from above, it’s relatively similar to HttpService:RequestAsync.

  • JSON.dumps does the same as HttpService:JSONEncode()
  • requests is almost like HttpService
  • try-except block is similar to most other languages (which use a try-catch block. Lua is the odd one out with pcall).

Comparing:

HttpService:RequestAsync({
    Url = --url,
    Headers = {
        ["x-api-key"] = apiKey,
        ["content-type"] = "application/json"
    },
    Body = HttpService:JSONEncode({})
})

As for python itself as a programming language, it is slightly different in terms of syntax.

  • You don’t need a variable initialiser
  • Subprograms are declared with the def keyword
  • Python is a whitespace language, which means it determines what code belongs to what scope based off of indentation. You need to make sure your indentation is correct.
def someFunc(param):
    pass #use pass when you don't want to put any code there

if (value):
    #things
elif (otherValue):
    #other things

#and so on.

In fact, you could probably write some code in Luau and ask an AI to translate it into Python. It’s worth a try.