[英]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]});
单击按钮时:
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();
});
}
});
如何删除单击按钮的消息? (DM)
我找不到从 dm 发送的消息的频道。
日志:
TypeError: Cannot read properties of undefined (reading 'fetch')
根据文档,有一个可供您使用的interaction.channel
属性:
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(); // :)
}
过于复杂的版本:从interaction
中获取消息并使用delete()
方法将其删除
简单/勺子喂养版本: interaction.message.delete();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.