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
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:
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.
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)
}
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.
I still cant really make my bot work… I am currently using a 3rd Party Visual Bot Programmer (Because I lack skills in python ) 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.
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.
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.