![](/img/trans.png)
[英]UnhandledPromiseRejectionWarning TypeError: Cannot read property 'property' of undefined
[英]UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of undefined
我尝试为我的 discord Bot 创建删除/修剪/清除命令,但在 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.
}```
它显示嵌入错误,因为在您的代码 at.then(message) 中,这意味着您将代替 value then is message 但它不重视 message 它是 then 的 value name message
.then(message => message.channel.send(embedPRUNE)).then(d => d.delete({timeout: 15000})) // In quanto tempo questo messaggio verrà eliminato (in ms).
然后需要改成其他值或者使用()
试试这个代码
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 ${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.channel.send(embedPRUNE)).then(d => d.delete({timeout: 15000})).catch(() => message.channel.send(embedERRPRUNE5))
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.