【问题标题】:UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of undefinedUnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“发送”
【发布时间】: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


    【解决方案1】:

    它显示嵌入错误,因为在您的 .then(message) 代码中,这意味着您将而不是 value then 是 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))
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-20
      • 2021-04-18
      • 2020-11-11
      • 1970-01-01
      • 1970-01-01
      • 2021-09-28
      • 2021-05-18
      • 2021-01-15
      相关资源
      最近更新 更多