检查在discordjs中是否已删除消息。

huangapple go评论73阅读模式
英文:

Check if a message has been deleted in discordjs

问题

我有一个 Discord.js 中的机器人,我正在尝试检查交互回复消息是否已被删除,以避免“未知消息”错误。

英文:

I have a bot in discordjs and I'm trying to check if the interaction.reply message has been deleted or not to avoid "Unknown Message" Errors

答案1

得分: 1

使用try-catch,您可以捕获错误,如果消息被删除

try {
  const message = await interaction.reply('message');
  console.log('Message not deleted');
} catch (error) {
  console.error('Message deleted');
}
英文:

using a try-catch you can catch the error if the message was deleted

try {
  const message = await interaction.reply('message');
  console.log('Message not deleted');
} catch (error) {
  console.error('Message deleted');
}

huangapple
  • 本文由 发表于 2023年2月7日 02:28:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75365235.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定