From 98ea70d35b6a2b52510a09bbe204cabe1831c2ff Mon Sep 17 00:00:00 2001 From: supositware Date: Mon, 20 Jun 2022 11:42:20 +0200 Subject: [PATCH] owner command --- commands/owner/die.js | 22 ++++++++++++++++++++++ deploy-owner-commands.cjs | 18 ++++++++++++++++++ index.js | 7 ++++--- 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 commands/owner/die.js create mode 100644 deploy-owner-commands.cjs diff --git a/commands/owner/die.js b/commands/owner/die.js new file mode 100644 index 00000000..9caf89a8 --- /dev/null +++ b/commands/owner/die.js @@ -0,0 +1,22 @@ +import { SlashCommandBuilder } from '@discordjs/builders'; +import dotenv from 'dotenv'; +import process from 'node:process'; +dotenv.config(); +const { ownerId } = process.env; + +export default { + data: new SlashCommandBuilder() + .setName('die') + .setDescription('Kill the bot'), + async execute(interaction) { + if (interaction.user.id !== ownerId) { + return interaction.reply({ content: '❌ This command is reserved for the owner!', ephemeral: true }); + } + console.log('\x1b[31m\x1b[47m\x1b[5mSHUTING DOWN!!!!!\x1b[0m'); + await interaction.reply({ content: 'Good bye', ephemeral: true }) + .then(() => { + console.log('\x1b[31m\x1b[47m\x1b[5mSHUTING DOWN!!!!!\x1b[0m'); + process.exit(1); + }); + }, +}; diff --git a/deploy-owner-commands.cjs b/deploy-owner-commands.cjs new file mode 100644 index 00000000..8351ea84 --- /dev/null +++ b/deploy-owner-commands.cjs @@ -0,0 +1,18 @@ +const { SlashCommandBuilder } = require('@discordjs/builders'); +const { REST } = require('@discordjs/rest'); +const { Routes } = require('discord-api-types/v9'); +require('dotenv').config(); +const { clientId, guildId, token } = process.env; + +const commands = [ + new SlashCommandBuilder() + .setName('die') + .setDescription('Kill the bot'), +] + .map(command => command.toJSON()); + +const rest = new REST({ version: '9' }).setToken(token); + +rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands }) + .then(() => console.log(`Successfully registered application commands for the guild ${guildId}.`)) + .catch(console.error); diff --git a/index.js b/index.js index 3c3bdd3e..93f32693 100644 --- a/index.js +++ b/index.js @@ -9,16 +9,17 @@ const { token } = process.env; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); -const client = new Client({ intents: [Intents.FLAGS.GUILDS] }); +const client = new Client({ intents: [Intents.FLAGS.GUILDS], shards: 'auto' }); // Load commands client.commands = new Collection(); await loadCommandFromDir('fun'); await loadCommandFromDir('utility'); +await loadCommandFromDir('owner'); // Load events -loadEventFromDir('client', client); -loadEventFromDir('process', process); +await loadEventFromDir('client', client); +await loadEventFromDir('process', process); client.login(token);