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

530
Visualizações
Delete Button/Component of a specifc message (discord.js)

I am now trying in vain to remove buttons from a bot message. I have created a command for this purpose. When executing it, it should at best remove a specific, the last or at least all buttons that are on a specific message.

I have tried various things, but in all attempts the buttons are not removed.

module.exports = {
category: 'Utilities',
description: 'Delete Buttons',
permissions: ['ADMINISTRATOR'],

callback: async ({ client, message }) => {
    const channel = client.channels.cache.get('the channel id')
    channel.messages.fetch('the message id').then(msg => msg.edit({components: []}));
    console.log(msg)
    }
}

When I try to do this, I get the following console error:

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

When I try this, I neither get a console log, nor does the bot do anything ...

const { Client, Message } = require("discord.js");

module.exports = {
  category: 'Utilities',
  description: 'Delete Buttons',

  permissions: ['ADMINISTRATOR'],

callback: async ({ client, message }) => {
    client.on('ready', async () => {
            const channel = client.channels.cache.get('the channel id')
                channel.messages.fetch('the message id').then(msg => {
                msg.edit({ components: [] })
            });
        },
    )}
  }

Maybe one of you knows a solution or an idea. :) Thanks a lot!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

When I try this, I neither get a console log, nor does the bot do anything

The second example does not do anything because you are creating a ready event handler on running your command. Meaning, it's waiting for the bot to once again be "ready", i.e. the state of having logged in to the API as it does on startup. But your bot is already ready, and will not become ready again until the next time it restarts, so nothing will happen.

As for the first example, the error you are getting suggests channel is undefined, meaning either:

A) You have the incorrect channel ID
- OR -
B) The specified channel is no longer in the channel cache

If you are 100% sure the ID is correct, we can assume the issue you are having is the latter (the channel not being in the cache). There are many ways to solve this, but one simple way is to simply fetch the channel similar to how you are trying to fetch the message. Here's an example:

const channel = await client.channels.fetch('the channel id');
const msg = await channel.messages.fetch('the message id');
msg.edit({components: []});

That should fix the issue. If it doesn't, then the issue is much more complicated and not enough information has been provided. Also note that in the above example, I swapped Promise syntax for async/await since you are using an async function anyways; I did this just to make this answer more readable, you can choose whichever format you prefer.

about 4 years ago · Juan Pablo Isaza Relatório
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