javascript - 无法读取未定义和未处理的 promise 拒绝的属性 'catch'

标签 javascript promise try-catch bots discord.js

有人知道如何修复这些错误吗,因为我不知道,我尝试了几种方法,但没有任何效果。顺便说一句,我是一个初学者。

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.

最佳答案

correct syntax是:

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

关于javascript - 无法读取未定义和未处理的 promise 拒绝的属性 'catch',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61269140/

相关文章:

javascript - Ember 无法读取未定义的属性 'find'

javascript - 如何让 rails rails_xss 停止转义我的模板 Javascript?

javascript - 我可以将 ajax 放在 React 组件构造函数中吗?

javascript - promise -如何处理已知错误

c# - 如何在引发异常之前将错误消息传递回

python - python中的嵌套try语句?

javascript - 滚动事件上的 jQuery .addClass() 不起作用

javascript - HTMLImageElemen.src 在哪里处理 HTMLImageElemen?

javascript - 处理 promise 中的错误

java - 在 catch block 中抛出相同的异常