【问题标题】:Discord JS/MongoDB SyntaxError: Unexpected token '}'Discord JS/MongoDB SyntaxError: Unexpected token '}'
【发布时间】:2020-12-09 14:51:30
【问题描述】:

我在尝试添加 else if() 函数时遇到了问题(我认为这就是它的名称),但一旦我这样做,就会遇到烦人的错误!

这是原始代码,

if(command === 'clue1') {
            client.commands.get('clue1').execute(message, client); 
            await configDB.updateOne({
                Clue_1: "True"
            })

            const collection = db.collection('clues')

            if(collection.find({ _id: ("ID HERE") }, {Clue1_Status: "True"}, (err, data) => {
                if (err) console.error(err)
                  return !data;
                })
              )
              return
            
              
            collection.find({ _id: ("ID HERE") }, {Clue1_Status: "False"}, async (err, data) => {
                if (err) console.error(err)
                if (data) {
                    const embed1 = new MessageEmbed()

                    .setTitle(`:partying_face: ${message.author.tag}` + " Just solved `Clue 1` :partying_face:")
                    .setColor(0xFFFF00)
                    client.channels.fetch("Channel ID")
                    .then(message => 
                        message.send(embed1)
                    )
                    await configDB1.updateOne({
                    Clue1_Status : "True"
                    })
                }
            })
    }
             

这是我要更改的代码:

if(command === 'clue1') {
            client.commands.get('clue1').execute(message, client); 
            await configDB.updateOne({
                Clue_1: "True"
            })

            const collection = db.collection('clues')

            if(collection.find({ _id: ("ID HERE") }, {Clue1_Status: "True"}, (err, data) => {
                if (err) console.error(err)
                  return !data;
                })
              )
              return
            
              
            collection.find({ _id: ("ID HERE") }, {Clue1_Status: "False"}, async (err, data) => {
                if (err) console.error(err)
                if (data) {
                    const embed1 = new MessageEmbed()

                    .setTitle(`:partying_face: ${message.author.tag}` + " Just solved `Clue 1` :partying_face:")
                    .setColor(0xFFFF00)
                    client.channels.fetch("Channel ID")
                    .then(message => 
                        message.send(embed1)
                    )
                    await configDB1.updateOne({
                    Clue1_Status : "True"
                    })
                }
            })
            )} 

但我得到SyntaxError: Unexpected token '}'

(出于隐私原因,我删除了一些代码(ID 等))

【问题讨论】:

    标签: node.js mongodb discord.js


    【解决方案1】:

    我想你只是在最后一行打错了。尝试将)} 更改为}

    【讨论】:

    • 嗯,我还是得到SyntaxError: Unexpected token '}'
    • 第 130 行 - Clue1_Status : "True" }) } }) --> } 抱歉,格式化
    • 好的,所以它确实与最后一行有关。
    • 当我将你的代码粘贴到我的代码中以检查 linting 错误时,我得到一个 Unexpected token )} 指向括号而不是括号,你没有包含的任何私有代码都可以吗和它有什么关系?
    • 其实...我发现collection.find({ ... Clue1_Status: "False"}... 似乎是问题所在,无论是尝试使用 if() 函数还是数据库本身...
    猜你喜欢
    • 2016-08-12
    • 2021-11-02
    • 1970-01-01
    • 2023-03-04
    • 2020-11-02
    • 2017-06-10
    • 1970-01-01
    • 2012-05-17
    • 2019-02-10
    相关资源
    最近更新 更多