mirror of
https://github.com/aydenjahola/discord-multipurpose-bot.git
synced 2025-02-22 17:44:39 +00:00
49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
const { SlashCommandBuilder, PermissionsBitField } = require("discord.js");
|
|
const { Rcon } = require("rcon-client");
|
|
|
|
module.exports = {
|
|
data: new SlashCommandBuilder()
|
|
.setName("whitelist")
|
|
.setDescription("Auto-whitelist a user on the Minecraft server")
|
|
.addStringOption((option) =>
|
|
option
|
|
.setName("username")
|
|
.setDescription("The Minecraft username to whitelist")
|
|
.setRequired(true)
|
|
),
|
|
isModOnly: true,
|
|
|
|
async execute(interaction) {
|
|
// Check if the user has the Manage Server permission
|
|
if (
|
|
!interaction.member.permissions.has(PermissionsBitField.Flags.ManageGuild)
|
|
) {
|
|
await interaction.reply({
|
|
content: "You do not have permission to use this command!",
|
|
ephemeral: false,
|
|
});
|
|
return;
|
|
}
|
|
|
|
const username = interaction.options.getString("username");
|
|
await interaction.deferReply();
|
|
|
|
try {
|
|
const rcon = new Rcon({
|
|
host: process.env.RCON_HOST,
|
|
port: Number(process.env.RCON_PORT),
|
|
password: process.env.RCON_PASSWORD,
|
|
});
|
|
await rcon.connect();
|
|
const response = await rcon.send(`whitelist add ${username}`);
|
|
await rcon.end();
|
|
|
|
await interaction.editReply(`RCON Response: ${response}`);
|
|
} catch (error) {
|
|
console.error("RCON Error:", error);
|
|
await interaction.editReply(
|
|
"There was an error executing the whitelist command."
|
|
);
|
|
}
|
|
},
|
|
};
|