Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

289
Visualizações
TypeError: Cannot read properties of undefined (reading 'destroy')

I get this error:

TypeError: Cannot read properties of undefined (reading 'destroy')

When running this code:

const { SlashCommandBuilder } = require("@discordjs/builders");
require('dotenv').config()

module.exports = {
    data: new SlashCommandBuilder()
    .setName("restart")
    .setDescription("Restarts the bot."),
    async execute(interaction, args, client) {
        let isBotOwner = interaction.user.id == '847213179142799452';

        if (isBotOwner) {
            interaction.reply('Restarting...').then(m => {
                client.destroy().then(() => {
                client.login(process.env.TOKEN);
              });
          });

        } else {
            interaction.reply('You cannot run this command unless you are the developer of me.')
        }
    }
}

The error is on client.destroy(). I've been looking in the docs and guides and on google but can't find anything on how to get it to work.

Could it be because I'm trying to destroy the client through a slash command?

Here is the command/interaction handler:

const {
    Client,
    Collection,
    Intents
} = require('discord.js');
const client = new Client({
    intents: [Intents.FLAGS.GUILDS]
});
const fs = require('fs');
require('dotenv').config()


client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

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
    client.commands.set(command.data.name, command);
}

client.on('interactionCreate', async interaction => {
    if (!interaction.isCommand()) return;

    const command = client.commands.get(interaction.commandName);

    if (!command) return;

    try {
        await command.execute(interaction);
    } catch (error) {
        console.error(error);
        await interaction.reply({
            content: 'There was an error while executing this command!',
            ephemeral: true
        });
    }
});
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda