当用户做出反应时,Discord Bot 不发送消息
Posted
技术标签:
【中文标题】当用户做出反应时,Discord Bot 不发送消息【英文标题】:Discord Bot doesnt send message when user reacts 【发布时间】:2020-07-31 06:57:28 【问题描述】:因此,即使用户应该做出反应,我的机器人也不会发送消息,然后出现错误...顺便说一句,由于 promise 拒绝错误,我在代码中放了很多 .catch 错误
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.`)
.catch(err => console.log('err1'))
.then(function (message)
message.react("????")
.catch(err => console.log(err));
message.react("????")
.catch(err => console.log(err));
message.awaitReactions((reaction, user) => user.id == message.author.id && (reaction.emoji.name == '????' || reaction.emoji.name == '????'),
max: 1)
.catch(err => console.log(err))
.then(collected =>
if (collected.first().emoji.name == '????')
message.send('Ok, so you want to buy a server. Let me recommend you to visit <#699374469977735208>.')
.catch(err => console.log(err));
else
message.send('Ok, so you need more informations first. Let me recommend you to visit <#699374469977735208>.')
.catch(err => console.log(err));
)
);
catch (err)
console.log(err)
)
以下是我不知道如何解决的错误:
(node:31944) UnhandledPromiseRejectionWarning: TypeError: message.send is not a function
at C:\Users\nicos\OneDrive\Documents\Discord Bots\PotatoHost Bot\index.js:27:33
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:31944) 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:31944) [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】:没有 message.send()
这样的东西,你需要用 message.channel.send()
替换它
你一直在问类似这样的小问题,你需要阅读文档:https://discord.js.org/#/docs/main/stable/general/welcome
【讨论】:
以上是关于当用户做出反应时,Discord Bot 不发送消息的主要内容,如果未能解决你的问题,请参考以下文章