I have a constant error.

I’m trying to make my own discord bot< but i can’t login. I have added my Bot Token to Secrets but it doesn’t seem to work.

There is my code:

const Discord = require("discord.js")
const client = new Discord.Client()

client.on("ready", () => {
  console.log(`Logged in as ${client.user.tag}!`)
})

client.on("message", msg => {
  if (msg.content === "тян") {
    msg.reply("Шо те надо")
  }
})

client.login(process.enc.TOKEN)
//const mySecret = process.env['TOKEN'];
//console.log(mySecret);

This error continuously pops up

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

SyntaxError: Unexpected token '?'

Who can i solve this problem?

Update your version of Node, it’s older than that syntax and it doesn’t support it (you will be able to turn it on via a flag when you start Node with your current version, but it’s easier long run to upgrade)

Edit: I am assuming this is a Node project?

Hi @Sumrak !

Welcome to the forum!

I feel like this is a typo

Try process.env.TOKEN

1 Like

How can i update my Node version?

There are various methods to update node.js.
Perhaps the simplest is:

Alternatively you can run ‘pip install node’ from a compatible console.
This assumes you have pip installed.

Didn’t told before. I’m coding in replit.com

Ah. You can’t change the node version easily (there are ways to do it, but they’re not particularly friendly).

Answer is don’t use the nullish coalescing operator, it’s only saving you a line of code.

The version of Node on Replit doesn’t support it without passing flags to Node when it starts, and afaik you can’t do that. It’s 100× easier to just not use the feature you’re trying to use there.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.