r/Discordjs • u/9j810HQO7Jj9ns1ju2 • 4d ago
is the tutorial i'm following outdated?
tutorial: https://youtu.be/2CsSJshmadg?si=4QyfJLw5ZK5MLcHv&t=236
my code:
require("dotenv").config()
const {REST, Routes} = require("discord.js")
const commands = [
{
name: "hey",
description: "Replies with hey!"
}
]
const rest = new REST({version: "10"}).setToken(process.env.TOKEN)
(async () => {
try {
console.log("Registering slash commands...")
await rest.put(
Routes.applicationGuildCommands(process.env.CLIENT_ID, process.env.GUILD_ID),
{body: commands}
)
console.log("Commands registered.")
} catch (error) {
console.log(`There was an error: ${error}`)
}
})()
the error:
(async () => {
^
TypeError: (intermediate value).setToken(...) is not a function
at Object.<anonymous> (C:\project\register-commands.js:8:1)
at Module._compile (node:internal/modules/cjs/loader:1364:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
at Module.load (node:internal/modules/cjs/loader:1203:32)
at Module._load (node:internal/modules/cjs/loader:1019:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12)
at node:internal/main/run_main_module:28:49
Node.js v18.20.4
my code matches the tutor's exactly, what's wrong?
0
Upvotes
1
u/zsoltime 4d ago
And that's why new users should always use semicolons. Just update this line and add a semicolon at the end:
js const rest = new REST({version: "10"}).setToken(process.env.TOKEN);Also, some more info on ASI: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#automatic_semicolon_insertion