From 98f4afda2e99242531ec798c13546acef3225d5e Mon Sep 17 00:00:00 2001 From: Xargana Date: Sat, 10 May 2025 15:27:38 +0300 Subject: [PATCH] added /kys --- discord/commands/shutdown.js | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 discord/commands/shutdown.js diff --git a/discord/commands/shutdown.js b/discord/commands/shutdown.js new file mode 100644 index 0000000..c8d4ed1 --- /dev/null +++ b/discord/commands/shutdown.js @@ -0,0 +1,42 @@ +const { SlashCommandBuilder } = require('@discordjs/builders'); + +module.exports = { + data: new SlashCommandBuilder() + .setName('shutdown') + .setDescription('Shuts down the bot gracefully') + .setDefaultMemberPermissions(0), // Restricts to administrators only + + async execute(interaction) { + // Check if user has admin permissions + if (!interaction.member.permissions.has('ADMINISTRATOR')) { + return await interaction.reply({ + content: 'You do not have permission to use this command.', + ephemeral: true + }); + } + + await interaction.reply({ + content: 'Shutting down the bot. Goodbye!', + ephemeral: true + }); + + // Trigger the shutdown process + console.log(`Manual shutdown triggered by ${interaction.user.tag}`); + + // Give Discord API time to send the reply + setTimeout(async () => { + try { + // Get the bot instance + const bot = interaction.client; + + // Use the existing shutdown mechanism + await bot.sendShutdownNotification(`Manual shutdown triggered by ${interaction.user.tag}`); + await bot.stop(); + } catch (error) { + console.error('Error during shutdown command:', error); + } finally { + process.exit(0); + } + }, 1000); + }, +}; \ No newline at end of file