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

393
Visualizações
discord.js v13 Interaction button delete orginal message
const row = new Discord.MessageActionRow()
  .addComponents(
    new Discord.MessageButton()
      .setCustomId(`deletable`)
      .setLabel('❌')
      .setStyle(4)
  );

user.send({content: 'hi', components: [row]});

When the button is clicked:

client.ws.on('INTERACTION_CREATE', async (interaction) => {
  const {
    data: {
      custom_id
    }
  } = interation;

  if (custom_id && custom_id === "deletable") {
    let channel = await client.messages.fetch({
      around: interaction.message.id,
      limit: 1
    }).then((msg) => {
      const fetchedMsg = msg.first();
      console.log(msg);
      fetchedMsg.delete();
    });
  }
});

How can I delete the message that the button was clicked on? (DM)

I can't find the channel of messages sent from dm.

Log:

TypeError: Cannot read properties of undefined (reading 'fetch')
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

According to the docs, there is a interaction.channel property available for you to use:

if (custom_id && custom_id === "deletable") {
    const channel = interaction.channel;
    const fetchedMsg = await channel.messages.fetch({ around: interaction.message.id, limit: 1 });
    await fetchedMsg.delete();

    // Alternatively, you could also use this:
    await interaction.message.delete();  // :)
}
about 4 years ago · Juan Pablo Isaza Relatório

0

Over-complicated version: Get the message from interaction and use the delete() method to delete it

Simple/spoon-feeding version: interaction.message.delete();

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