CrashEng
CrashEng
DIAdiscord.js - Imagine an app
Created by CrashEng on 6/20/2023 in #djs-questions
cant get slash command to handle
const { SlashCommandBuilder } = require('discord.js'); module.exports = { data: new SlashCommandBuilder() .setName('ping') .setDescription('Replies with Paong!'), async execute(interaction) { await interaction.reply('Pong!'); }, };
10 replies
DIAdiscord.js - Imagine an app
Created by CrashEng on 6/20/2023 in #djs-questions
cant get slash command to handle
// Require the necessary discord.js classes const { Client, Events, Collection, GatewayIntentBits } = require('discord.js'); const fs = require('node:fs'); const path = require('node:path'); // Create a new client instance const client = new Client({ intents: [GatewayIntentBits.Guilds] }); client.commands = new Collection(); const foldersPath = path.join(__dirname, 'commands'); const commandFolders = fs.readdirSync(foldersPath); for (const folder of commandFolders) { const commandsPath = path.join(foldersPath, folder); const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js')); for (const file of commandFiles) { const filePath = path.join(commandsPath, file); const command = require(filePath); if ('data' in command && 'execute' in command) { client.commands.set(command.data.name, command); } else { console.log([WARNING] The command at ${filePath} is missing a required "data" or "execute" property.); } } } client.once(Events.ClientReady, () => { console.log('Ready!'); }); client.on(Events.InteractionCreate, async interaction => { if (!interaction.isChatInputCommand()) return; const command = client.commands.get(interaction.commandName); if (!command) return; try { await command.execute(interaction); } catch (error) { console.error(error); if (interaction.replied || interaction.deferred) { await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true }); } else { await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true }); } } }); // Log in to Discord with your client's token client.login(process.env.BOT_TOKEN);
10 replies
DIAdiscord.js - Imagine an app
Created by CrashEng on 6/20/2023 in #djs-questions
cant get slash command to handle
10 replies