Estoy tratando de crear un sistema de comando de barra para mi bot discord.js, pero no aparece en la aplicación
Aquí está el código que estoy usando
const { Client, Collection, Intents } = require('discord.js'); const client = new Client({ intents: [Intents.FLAGS.GUILDS] }); const fs = require('fs'); const { Routes } = require('discord-api-types/v9'); const { REST } = require('@discordjs/rest'); const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); const commands = []; // Creating a collection for commands in client client.commands = new Collection(); for (const file of commandFiles) { const command = require(`./commands/${file}`); commands.push(command.data.toJSON()); client.commands.set(command.data.name, command); } client.on('ready', () => { console.log(`Ready! Logged in as ${client.user.tag}`) for (const file of commandFiles) { const command = require(`./commands/${file}`); // Set a new item in the Collection // With the key as the command name and the value as the exported module console.log(`Loaded slash command /${command.data.name}.`) } const CLIENT_ID = client.user.id; const rest = new REST({ version: '9' }).setToken("myToken"); (async () => { try { await rest.put( Routes.applicationCommands(CLIENT_ID), { body: commands }, ); console.log('Successfully registered all application commands globally'); } catch (error) { if (error) console.error(error); } })(); }) client.on('interactionCreate', async interaction => { if (!interaction.isCommand()) return; const command = client.commands.get(interaction.commandName); if (!command) return; const { options } = interaction try { await command.execute(interaction, options, client); } catch (error) { console.error(error); await interaction.reply({ content: `ERROR: There was a problem executing the **${command.name}** command. Please try again later.`, ephemeral: true }); } }); client.login("myToken")Este es mi archivo de comando (Mi archivo ping.js)
const { SlashCommandBuilder } = require("@discordjs/builders"); module.exports = { data: new SlashCommandBuilder() .setName("ping") .setDescription("Ping Pong!"), async execute(interaction, options, client) { interaction.reply("Pong!") } }Cada vez que lanzo mi bot, no aparecen comandos de barra oblicua. Sin embargo, todas las cadenas se registran en la consola.
Le he dado al bot application.commands scope.