Hello everyone!
I am attempting to make a Discord to Roblox ranking bot (but will have more features), but the biggest problem I am having right now is trying to make it so the bot joins the group when they run the /setup command.
My command so far:
const { SlashCommandBuulder, EmbedBuilder, ModalBuilder, ActionRowBuilder, TextRowBuilder } = require('discord.js');
const serverSchema = require('../../Models/Server.js');
const request = require('request');
module.exports = {
data: new SlashCommandBuilder()
.setName('setup')
.setDescription('Sets up the bot for your server.'),
async execute(interaction) {
const server = await serverSchema.findOne({ serverId: interaction.guild.id });
if (server.robloxGroupId == 0 && server.botJoined == false) {
const setupModal1 = new ModalBuilder()
.setCustomId('setupModal1')
.setTitle('Setup');
const robloxGroupIdInput = new TextRowBuilder()
.setCustomId('robloxGroupIdInput')
.setLabel('Roblox Group ID')
.setStyle(1)
.setPlaceholder('Enter the Roblox Group ID')
.setRequired(true);
const robloxGroupIdActionRow = new ActionRowBuilder()
.addComponents(setupModal1);
setupModal1.addComponents(robloxGroupIdActionRow);
const filter = (interaction) => interaction.customId === 'setupModal1';
const collector = interaction.channel.createMessageComponentCollector({ filter, time: 60000 });
if (interaction.isModalSubmit()) {
const robloxGroupId = interaction.fields.getTextInputValue('robloxGroupIdInput');
if (isNaN(robloxGroupId)) {
await interaction.reply({ content: 'Invalid Roblox Group ID. Please enter a valid number.', ephemeral: true });
return;
}
try {
const headers = { authorization: `Bearer ${process.env.ROBLOX_API_KEY}`,"content-type": "application/json"" };
await request.get(`https://groups.roblox.com/v1/groups/${robloxGroupId}`, {
method: "POST",
headers: headers,
json: true,
}, async (error, response, body) => {
if (error) {
console.error(error);
await interaction.reply({ content: 'An error occurred while checking the Roblox Group ID.', ephemeral: true });
return;
}
if (response.statusCode === 200) {
const server = await serverSchema.findOne({ serverId: interaction.guild.id });
if (server) {
server.robloxGroupId = robloxGroupId;
await server.save();
} else {
const newServer = new serverSchema({
serverId: interaction.guild.id,
robloxGroupId: robloxGroupId,
});
await newServer.save();
}
await interaction.reply({ content: 'Roblox Group ID set successfully.', ephemeral: true });
} else {
await interaction.reply({ content: 'Invalid Roblox Group ID. Please enter a valid number.', ephemeral: true });
}
}
}catch (error) {
}
}
}
},
};
If someone could help me with this command that would be great.
Thanks,
Joe