'How to solve error "SyntaxError: Unexpected token '?'"

I'm not sure what's wrong. I deleted my code and downloaded it then uploaded it again and now I get this error.

Code: https://replit.com/@hi12167pies/webcord#index.js (Click code for code and output for output)

Error:

/home/runner/C8AU9ceLyjc/node_modules/discord.js/src/rest/RESTManager.js:32
    const token = this.client.token ?? this.client.accessToken;
                                     ^

SyntaxError: Unexpected token '?'

I have no idea whats wrong since it's in the node_modules folder.

If you have problems viewing it here is the code:

const http = require("http")
const discord = require("discord.js")
const client = new discord.Client()
const config = require("./config.json")
const fs = require("fs")
// const readLine = require("readline")
// const rl = readLine.createInterface({
//   input: process.stdin,
//   output: process.stdout
// })

let msgs = {
  "873195510251532348": [],
  "873195522633105429": []
}


client.on("ready", () => {
  console.log("ready discord")
})

client.on("message", (message) => {
  if (message.author.bot) return
  if (!config.chats.includes(message.channel.id.toString())) return

  msgs[message.channel.id].push({
    "username": message.author.tag,
    "content": message.content,
    "type": "0"
  })
})

http.createServer((req,res) => {
  const url = req.url.split("?")[0]
  let query = {}
  req.url.slice(req.url.split("").indexOf("?")).slice(1).split("&").forEach((e) => {
    const splited = e.split("=")
    query[splited[0]] = splited[1]
  })

  if (query.q == "messages") {
    let msg = []

    let i = 0
    while (msgs[query.code].length > i) {
      const e = msgs[query.code][msgs[query.code].length - (i+1)]
      msg.push(e)
      i++
    }

    res.write(JSON.stringify(msg))
    res.end()
  } else if (query.q == "post") {
    let name = query.name.split("%20").join(" ")
    let content = query.content.split("%20").join(" ")
    client.channels.cache.get(query.code).send(`**${name}**: ${content}`)
    msgs[query.code].push({
      "username": name,
      "content": content,
      "type": "1"
    })
    res.end()
  } else if (url == "/robot" && query.istrue == "true") {
    res.write("Robot!")
    res.end()
  } else {
    let path
    if (!query.code) {
      path = "./code.html"
    } else {
      if (!config.chats.includes(query.code)) {
        path = "./invaildcode.html"
      } else {
        path = "./chat.html"
      }
    }
    fs.readFile(path, (er, da) => {
      if (er) res.write("Could not get index.html")
      res.write(da)
      res.end()
    })
  }


}).listen(80, (err) => {
  if (err) throw err
  console.log("listening webserver")
})

client.login(process.env.TOKEN)

I am aware my code is not good right now, I am rewriting it but I still want to know what the error is.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source