Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

605
Vistas
Discord.js „The application did not respond“

I know this is a duplicate but it is a specific issue i think.

I am getting an error while performing a slash command: „The application did not respond“.

What I am trying to do is an Slash Command, that can only be performed by someone with the Administrator Role. The command should be give the User role to the mentioned user.

If someone knows a better way to do that or a GitHub Link etc. I would like to see this as well. Anyway - here is my code:

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)

Thanks.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda