对机器人发出的消息的反应=机器人发出的新消息

时间:2020-04-15 17:51:09

标签: javascript bots discord discord.js message

那我遗漏了什么或忘记了什么?我希望机器人在用户对旧消息做出反应时发送新消息。该漫游器已经对自己的消息做出了反应,因此用户只需单击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.

1 个答案:

答案 0 :(得分:2)

如错误所示,您正在尝试通过行dmErr = true对常量进行赋值。 dmErr被声明为const。如果您打算覆盖变量的值,则应将其更改为let