I recently made a discord bot and would like to know how I can integrate it to Roblox (beginner in web development). Code is also pretty messy so I want to start over based on your feedback
Explaination
What I have currently:
If I try to enter another command without restarting the bot and the Roblox game:
(Still prints two in the console)
Here’s my attempt at fixing this (got messy):
Code
if (command == "robloxmessage") {
if (args[0] && args.length <= 1) {
if (!startedServer) {
console.log("Server started at http://localhost:8000")
message.channel.send("Initializing remote server.")
server = app.listen(port)
message.channel.send("Initialized remote server.")
console.log("Server listening on port.")
startedServer = true;
try {
app.post('/post', (request, response) => { //send a post request to the url
response.send(`${args[0]}`) //send (post)
console.log(request.body) //log roblox response
setTimeout(function () {
server.close();
// ^^^^^^^^^^^
}, 3000)
})
}
catch (error) {
console.log(`Roblox Event command error ${error}`)
message.reply(`Try again or contact Johnapolitan#7935`)
}
console.log(`${startedServer}`)
} else {
const sockets = new Set();
server.on('connection', (socket) => {
sockets.add(socket);
server.once('close', () => {
sockets.delete(socket);
});
});
/**
* Forcefully terminates HTTP server.
*/
const close = (callback) => {
for (const socket of sockets) {
socket.destroy();
sockets.delete(socket);
}
server.close(callback);
};
try {
app.post('/post', (request, response) => { //send a post request to the url
response.send(`${args[0]}`) //send (post)
console.log(request.body) //log roblox response
})
}
catch (error) {
console.log(`Roblox Event command error ${error}`)
message.reply(`Try again or contact Johnapolitan#7935`)
}
}
} else {
return message.channel.send(`Please provide the proper arguments. Use !help to see them.`);
}
}```
Already tried: Forcing the server to close and using server.close()
To be honest, the code is at the point where it needs to be rewritten so if you’ve done this before I can just do it again of your response.