I haven’t found any solutions to my problem yet. Using the messagingService API, I’m trying to do commands from discord using discord.js and node.js
But, my code doesn’t get any responses. Tried debugging and other things, but nothing worked. Here’s my code
local MessagingService = game:GetService("MessagingService");
local HttpService = game:GetService("HttpService");
MessagingService:SubscribeAsync("DJSK", function(message)
local Decoded = HttpService:JSONDecode(message);
print(Decoded.message);
end);
It doesn’t work at all. Please help.
jake_4543
(Jakey)
October 27, 2022, 4:25pm
#2
whats the code your using to send to messaging service
I’ve checked multiple times whether the url is wrong or not. But it’s correct.
const { SlashCommandBuilder } = require("discord.js");
const fetch = require("node-fetch-commonjs");
module.exports = {
data: new SlashCommandBuilder()
.setName("robloxkick")
.setDescription("Kick user on Roblox.")
.addStringOption(option =>
option
.setName("username")
.setDescription("Type in the user's name.")
.setRequired(true)
)
.addStringOption(option =>
option
.setName("reason")
.setDescription("Type in the reason.")
.setRequired(false)
),
async run(interaction) {
await fetch(
"https://apis.roblox.com/messaging-service/v1/universes/4017485445/topics/DJSK",
{
method: "POST",
headers: {
"x-api-key": process.env.API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({
// "Username": interaction.options.getString("username"),
// "Reason": (interaction.options.getString("reason") | "No reason provided."),
message: interaction.options.getString("username"),
}),
},
);
try {
await interaction.reply(`Successfully kicked out '${interaction.options.getString("username")}'`);
} catch (err) {
console.error(err);
await interaction.reply(`Unable to kick out '${interaction.options.getString("username")}'`);
};
},
};
jake_4543
(Jakey)
October 27, 2022, 4:27pm
#4
do you have your allowed ips set to 0.0.0.0?
Yep.
I’ve been in this problem for the last 2 days ._.
Going to sleep, so if here’s the API info if you need it.
jake_4543
(Jakey)
October 27, 2022, 4:32pm
#6
are you testing this in studio or in-game?
In-game including API Services enabled.
Is the name of your message your subscribing to correct? It looks like spam.
Did you test this code in a public server?
Did you confirm that you’re sending data to the correct roblox URL using discord.js?
Sorry, I was asleep.
Everything is correct. In the code, my topic is DJSK, referring to d iscord.js -k ick.
I did. And by public server, do you mean that my game has to be public or it can be private?
I can’t fully confirm that as I’m getting absolutely no response.
I’ve tried regenerating my API key, but it didn’t work at all.
Need some help. Been stuck on this problem for days ;-;
Finally fixed it. I used the axios package instead of fetch, and it worked. I really was pretty dumb to not try out other packages.
system
(system)
Closed
November 12, 2022, 6:23am
#12
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.