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

Posted

技术标签:

【中文标题】无法读取未定义和未处理的承诺拒绝的属性“捕获”【英文标题】:Cannot read property 'catch' of undefined and Unhandled promise rejection 【发布时间】:2020-07-30 19:23:42 【问题描述】:

有人知道如何修复错误吗,因为 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】:

correct syntax 是:

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

【讨论】:

以上是关于无法读取未定义和未处理的承诺拒绝的属性“捕获”的主要内容,如果未能解决你的问题,请参考以下文章

具有未定义和空值的排序对象数组

Firefox 4 中的 JQuery 未定义和 $ 未定义错误 [关闭]

GetOrgChart:尚未定义父节点的节点

成员变量 - 未定义和不可访问

比较未定义和错误的非常奇怪的行为

未捕获的引用错误,未定义通知