对来自机器人的消息的反应=来自机器人的新消息
Reaction to a message from the bot=new message from the bot
那么我遗漏了什么或忘记了什么?我希望当用户对旧消息做出反应时,机器人会发送一条新消息。机器人已经对他的消息做出了反应,因此用户只需单击 A 或 B 即可做出反应。
const Discord = require('discord.js');
const { prefix, token } = require('./config.json');
const client = new Discord.Client();
client.on('ready', () => {
console.log('Ready!');
})
client.on("guildMemberAdd", async member => {
const dmErr = false;
try {
await 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("")
const filter = (reaction, user) => {
return ['', ''].includes(reaction.emoji.name) && user.id === message.author.id;
};
})
message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
.then(collected => {
const reaction = collected.first();
if (reaction.emoji.name === '') {
message.reply('Ok, so you want to buy a server. Let me recommend you to visit <#699374469977735208>.');
}
else {
message.reply(`Ok, so you need more informations first. Let me recommend you to visit <#699374469977735208>.`);
}
})
.catch(function (message) {
console.error('One of the emojis failed to react, or the user has dms disabled.')
})
} catch (error) {
dmErr = true;
} if (dmErr === true) {
console.log(error)
}
});
client.login(token);
这是错误:
(node:19044) UnhandledPromiseRejectionWarning: TypeError: Assignment to constant variable.
at Client.<anonymous> (C:\Users\nicos\OneDrive\Documents\Discord Bots\PotatoHost Bot\index.js:41:15)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:19044) 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:19044) [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.
如错误所述,您正在尝试使用行 dmErr = true
对常量变量进行赋值。 dmErr
声明为 const
。如果您打算覆盖变量的值,则应将其更改为 let
。
那么我遗漏了什么或忘记了什么?我希望当用户对旧消息做出反应时,机器人会发送一条新消息。机器人已经对他的消息做出了反应,因此用户只需单击 A 或 B 即可做出反应。
const Discord = require('discord.js');
const { prefix, token } = require('./config.json');
const client = new Discord.Client();
client.on('ready', () => {
console.log('Ready!');
})
client.on("guildMemberAdd", async member => {
const dmErr = false;
try {
await 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("")
const filter = (reaction, user) => {
return ['', ''].includes(reaction.emoji.name) && user.id === message.author.id;
};
})
message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
.then(collected => {
const reaction = collected.first();
if (reaction.emoji.name === '') {
message.reply('Ok, so you want to buy a server. Let me recommend you to visit <#699374469977735208>.');
}
else {
message.reply(`Ok, so you need more informations first. Let me recommend you to visit <#699374469977735208>.`);
}
})
.catch(function (message) {
console.error('One of the emojis failed to react, or the user has dms disabled.')
})
} catch (error) {
dmErr = true;
} if (dmErr === true) {
console.log(error)
}
});
client.login(token);
这是错误:
(node:19044) UnhandledPromiseRejectionWarning: TypeError: Assignment to constant variable.
at Client.<anonymous> (C:\Users\nicos\OneDrive\Documents\Discord Bots\PotatoHost Bot\index.js:41:15)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:19044) 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:19044) [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.
如错误所述,您正在尝试使用行 dmErr = true
对常量变量进行赋值。 dmErr
声明为 const
。如果您打算覆盖变量的值,则应将其更改为 let
。