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

386
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
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