无法读取未定义和未处理的承诺拒绝的属性“捕获”
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);
【讨论】:
以上是关于无法读取未定义和未处理的承诺拒绝的属性“捕获”的主要内容,如果未能解决你的问题,请参考以下文章