【发布时间】:2021-04-09 17:04:35
【问题描述】:
我尝试为我的 discord Bot 创建 Delete/prune/purge 命令,但在 bot 删除消息后,它没有响应我创建的消息,但此错误出现在日志中:UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of undefined
我也尝试将其放入命令中:.catch(() => message.channel.send(embedERRPRUNE5))
但他回复的是错误消息而不是成功消息。
这是代码:
if (msg.startsWith(prefix + "prune") || msg.startsWith(prefix + "purge") || msg.startsWith(prefix + "delete")) {
...
var embedERRPRUNE5 = new Discord.MessageEmbed()
.setColor("#8c00ee")
.setTitle("❌Something went wrong, while deleting messages.")
.setAuthor("Vittorio De Stradis ツ", "https://cdn.discordapp.com/attachments/784128595084705853/790590227277545502/Cowboy_Bepop_1.png", "...")
.setFooter("If you need help, pls contact me!", "https://cdn.discordapp.com/attachments/784128595084705853/790590227277545502/Cowboy_Bepop_1.png")
.setTimestamp();
var embedPRUNE = new Discord.MessageEmbed()
.setColor("#8c00ee")
.setTitle(`✔ Deleted ${message.size}/${args[0]} messages.`)
.setAuthor("Vittorio De Stradis ツ", "https://cdn.discordapp.com/attachments/784128595084705853/790590227277545502/Cowboy_Bepop_1.png", "...")
.setFooter("If you need help, pls contact me!", "https://cdn.discordapp.com/attachments/784128595084705853/790590227277545502/Cowboy_Bepop_1.png")
.setTimestamp();
await message.delete()
await message.channel.bulkDelete(args[0])
.then(message => message.channel.send(embedPRUNE)).then(d => d.delete({timeout: 15000})) // In quanto tempo questo messaggio verrà eliminato (in ms).
.catch(() => message.channel.send(embedERRPRUNE5)) // Questo errore comparirà quando il bot non ha l'accesso per farlo.
}```
【问题讨论】:
标签: javascript node.js visual-studio-code discord discord.js