When I send the request from discord to roblox I want to check if the player is in the server then if the player isn’t in the server, then return the request back to discord with saying Player not found within game servers
ROBLOX Code:
MS:SubscribeAsync("ServerKick", function(requestInfo)
local Data = requestInfo.Data
local DecodedData = HTTP:JSONDecode(Data)
local Plr = DecodedData.Username
local Reason = DecodedData.Reason
local player = Players:FindFirstChild(Plr)
if player then
player:Kick(Reason)
else
warn("Player not found: " .. Plr)
end
end)
Bot Code:
const { SlashCommandBuilder } = require('discord.js');
const { TestingServer } = require('../config.json');
const Axios = require(`axios`);
const messageSend = async (messageContent, reason) => {
const ObjectToSend = { 'Username': messageContent, 'Reason': reason };
try {
const response = await Axios.post("",
{ 'message': JSON.stringify(ObjectToSend) },
{
headers: {
'x-api-key': '',
'Content-Type': 'application/json'
}
});
console.log(response.data);
} catch (err) {
console.error(err.response ? err.response.data : err.message);
}
};
module.exports = {
data: new SlashCommandBuilder()
.setName('kick')
.setDescription('Kick a player')
.addStringOption(option =>
option.setName('username')
.setDescription('Enter the roblox username you that you wish to kick from the game.')
.setRequired(true))
.addStringOption(option =>
option.setName('reason')
.setDescription('The reason for kicking the player')
.setRequired(true)),
async execute(interaction) {
try {
if (interaction.guildId !== TestingServer) {
return interaction.reply({ content: 'This command can only be used in the Testing server!', ephemeral: true });
}
const messageContent = interaction.options.getString('username');
const reason = interaction.options.getString('reason');
await messageSend(messageContent, reason);
await interaction.reply({ content: `<:shieldcheck:1302715220757581914> Successfully sent kick request for player: **${messageContent}** and for the reason: **${reason}.**`, ephemeral: false });
} catch (error) {
console.error('Error executing kick command:', error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
};
if the player is in the game, then the code can proceed onwards