Sé que esto es un duplicado, pero creo que es un problema específico.
Recibo un error al ejecutar un comando de barra: "La aplicación no respondió".
Lo que estoy tratando de hacer es un Comando de Barra, que solo puede ser realizado por alguien con el Rol de Administrador. El comando debe ser dar el rol de Usuario al usuario mencionado.
Si alguien conoce una mejor manera de hacerlo o un enlace de GitHub, etc. Me gustaría ver esto también. De todos modos, aquí está mi código:
const DiscordJS = require('discord.js'); const { Routes } = require('discord-api-types/v9'); const { Intents, Client, MessageEmbed } = require('discord.js'); const { token, client_id, guild_id, admin_role_id, user_role_id } = require('./config.json') const client = new DiscordJS.Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES], }) client.on('ready', () => { console.log('The bot is ready') const guild = client.guilds.cache.get(guild_id) let commands if (guild) { commands = guild.commands } else { commands = client.application?.commands } commands?.create({ name: 'user', description: 'Makes the mentioned member a user.', requireRoles: true, options: [{ name: 'user', description: 'The user the role should be given to.', required: true, type: DiscordJS.Constants.ApplicationCommandOptionTypes.USER }] }) }) client.on('interactionCreate, a', async (interaction) => { if (!interaction.isCommand()) { return } const { commandName, options } = interaction if (commandName === 'user') { const user_id = options.get('user')?.value; const guild = client.guilds.cache.get(guild_id); if (!guild) { return console.log(`Can't find the guild with ID ${server_id}.`); } guild.members.fetch(user_id) .then(member => { console.log(member.roles.cache) const embedSuccess = new MessageEmbed() .setColor('#5ee067') .setDescription('<@' + user_id + '> was given the <@&' + user_role_id + '> role.'); const embedUserInfo = new MessageEmbed() .setDescription('Dear <@' + user_id + '>, \n you are able…'); const embedFailure = new MessageEmbed() .setColor('#ffa2a2') .setDescription("Could not perform command because the user that requested it doesn't have the required roles to execute it.") if (interaction.user.roles.cache.has(admin_role_id)) { const member = interaction.options.getMember('target'); member.roles.add(user_role_id) interaction.reply({ content: '<@' + user_id + '>', embeds: [ embedSuccess, embedUserInfo ] }) } else { interaction.reply({ embeds: [ embedFailure ] }) } }) .catch(console.error); } }) client.login(token)Gracias.