无法读取未定义和未处理的承诺拒绝的属性“ catch”

时间:2020-04-17 10:15:01

标签: javascript promise try-catch bots discord.js

有人知道如何解决错误,因为idk,我尝试了几件事,但没有任何效果。我是初学者。

client.on("guildMemberAdd", member => {
    try {
        member.send(`Hello ${member}, welcome to the PotatoHost Server! 
I want to help you and so my question is: Do you want to buy a server or do you need more informations first? \n
A: I want to buy a server
B: I need more informations first \n
Please react to this message with A or B.`)
        .then(function (message) {
            message.react("?")
            message.react("?")     
            message.awaitReactions((reaction, user) => user.id == message.author.id && (reaction.emoji.name == '?' || reaction.emoji.name == '?'),
                { max: 1}).then(collected => {
                    if (collected.first().emoji.name == '?') {
                        message.send.catch(err => console.log(err))('Ok, so you want to buy a server. Let me recommend you to visit <#699374469977735208>.');
                        client.destroy();
                    }
                    else
                        message.send.catch(err => console.log(err))('Ok, so you need more informations first. Let me recommend you to visit <#699374469977735208>.');
                })
        });
    }catch (err) {
         console.log(err)
    }
})

错误:

(node:26800) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'catch' of undefined
    at C:\Users\nicos\OneDrive\Documents\Discord Bots\PotatoHost Bot\index.js:22:38
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:26800) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:26800) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

1 个答案:

答案 0 :(得分:2)

correct syntax是:

message.channel.send('MESSAGE').catch(console.error);