UnhandledPromiseRejectionWarning: TypeError: Cannot read property ‘send’ of undefined

I tryed to create a Delete/prune/purge command for my discord Bot but after the bot deletes the messages it does not respond with the message I created but this error appears in the log: UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of undefined

I also tried to put this in the command: .catch(() => message.channel.send(embedERRPRUNE5))
But he replies with the error message instead of the success message.

This is the code:

    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.
    }```

Source: Ask Javascript Questions

LEAVE A COMMENT