const row = new Discord.MessageActionRow() .addComponents( new Discord.MessageButton() .setCustomId(`deletable`) .setLabel('❌') .setStyle(4) ); user.send({content: 'hi', components: [row]});Cuando se hace clic en el botón:
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(); }); } });¿Cómo puedo eliminar el mensaje de que se hizo clic en el botón? (DM)
No encuentro el canal de mensajes enviados desde dm.
Tronco:
TypeError: Cannot read properties of undefined (reading 'fetch')De acuerdo con los documentos , hay una propiedad de interaction.channel disponible para su uso:
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(); // :) }Versión demasiado complicada: obtenga el mensaje de la interaction y use el método delete() para eliminarlo
Versión simple/alimentación con cuchara: interaction.message.delete();