Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

384
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!