简体   繁体   中英

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

It show embed error because in your code at.then(message) in this it mean you will instead of value then is message but it doesn't value message it is value name message of then

.then(message => message.channel.send(embedPRUNE)).then(d => d.delete({timeout: 15000})) // In quanto tempo questo messaggio verrà eliminato (in ms).

Then you need to change to other value or use ()

Try this 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 ${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))
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM