#Erikost3 - TypeError rest.setToken is not a function

1 messages ยท Page 1 of 1 (latest)

stone robin
#

@uneven bison let us Continue with your problem here

uneven bison
#

Okay

stone robin
#

let me take a look :)

uneven bison
#

I'm pretty new to js so yeah that's why this problem is probably nothing big lmao

stone robin
#

but ya imported @discordjs/rest right?

npm i @discordjs/rest
uneven bison
#

No, my friend told me I already had it.

#

But I can do it.

stone robin
#

whats written in your package.json ?

uneven bison
#

yeah

#
{
  "name": "artifact",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@discordjs/builders": "^0.12.0",
    "@discordjs/rest": "^0.3.0",
    "discord-api-types": "^0.26.1",
    "discord.js": "^13.6.0",
    "dotenv": "^16.0.0",
    "mariadb": "^2.5.5"
  }
}
stone robin
#

okay, yea its imported

uneven bison
#

yeah

#

im really confused

#

the tutorial ran this completly fine

stone robin
#

me to, like I do

import { REST } from '@discordjs/rest';

and then I do

const rest = new REST({ version: '9' }).setToken(process.env.BOT_TOKEN);

that is ES6 Syntax, so Converted to Commonjs what you're using its

const { REST } = require('@discordjs/rest')
const rest = new REST({version: '9'}).setToken(process.env.BOT_TOKEN);
uneven bison
#

yeah

#

is there any way I can log the "rest" object to see what it contains?

stone robin
#

console.log(REST)

#

but that's properly something like [class de extends EventEmitter]

uneven bison
#

yes

stone robin
#

but you could instead do the console.log() of your rest constant like console.log(rest) directly after creating it

uneven bison
#

it does

#

im trying to look for setToken

stone robin
#

yea

uneven bison
#

it has none

#

breh

#

yours have no either

stone robin
#

yea, functions are nor listed there

uneven bison
#

now this is confusing

stone robin
#
uneven bison
#

hmmm

#

so is discord js down?

stone robin
#

no

uneven bison
#

oh

stone robin
#

just that part of the documentation

uneven bison
#

nice

stone robin
#

what do you get if ya console.log(rest.setToken);

#

i get [Function: setToken]

uneven bison
#

most likely null

stone robin
#

and?

uneven bison
#

wtf message [Function: setToken]

stone robin
#

so the funcction exists

uneven bison
#

it says it's not a function tho

#

TypeError: rest.setToken(...) is not a function

stone robin
#

oh, the ... s

uneven bison
#

huh?

stone robin
#

do you have a .env file? DONT SHARE THE TOKEN

uneven bison
#

yes

stone robin
#

and your token variable is exacctly called TOKEN=xyz?

uneven bison
#

I did TOKEN=token

#

yes

stone robin
uneven bison
#

no lol

#

i would love if that was the issue

stone robin
#

okay :)

uneven bison
#

I even tried printing the token

#

that worked

stone robin
#

if you cconsole log console.log(process.env.TOKEN) do you get your token in the cconsole

#

ahh okay :)

uneven bison
#

yep

stone robin
#

hmm

uneven bison
#

I actually used the wrong token before.

#

lmao

stone robin
#

okay?

uneven bison
#

I feel like there is something im missing on this line rest.setToken(process.env.TOKEN)

stone robin
#

no ther isnt really

uneven bison
#

hold up imma ask my other friend

stone robin
#

okay :)

uneven bison
#

he doesn't answer :(

#

so um

stone robin
#

https://www.npmjs.com/package/@discordjs/rest lul discordjs is using a deprecated package xD

uneven bison
#

huh

#

oh

stone robin
#

so this will not be the way much longer like its looking, but still it should work for you

uneven bison
#

oh

#

ohno

stone robin
#

still looks weird

uneven bison
#

so the tutorial im using is shit dam

stone robin
#

no

#

they litteraly use it in the official tutorial

uneven bison
#

hmm

#

um

stone robin
uneven bison
#

oh yeah

#

uhm but this works for u and not for me, then it means my package is wrong???

stone robin
#

would make sense

#
{
  "name": "botprefab",
  "version": "0.0.1",
  "description": "",
  "main": "index.ts",
  "scripts": {
    "test": "nodemon src/index.ts",
    "start": "node build/index.js",
    "build": "tsc"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/snoweuph/BotPrefab.git"
  },
  "keywords": [],
  "author": "",
  "license": "UNLICENSED",
  "bugs": {
    "url": "https://github.com/snoweuph/BotPrefab/issues"
  },
  "homepage": "https://github.com/snoweuph/BotPrefab#readme",
  "dependencies": {
    "@discordjs/builders": "^0.12.0",
    "@discordjs/rest": "^0.3.0",
    "discord-api-types": "^0.26.1",
    "discord.js": "^13.6.0",
    "dotenv": "^16.0.0",
    "mysql2": "^2.3.3",
    "node-fetch": "^3.2.0"
  },
  "devDependencies": {
    "@types/events": "^3.0.0",
    "nodemon": "^2.0.15"
  }
}
uneven bison
#

yeah same version omg

stone robin
#

yea I don't havy anymore ideas and I dont see anything that could be the problem, bu properly Im just blind, just asked in #djs-help-v14 if somone else could look onto it, sry)

uneven bison
#

thank you for trying tho ๐Ÿ‘Œ

stone robin
#

np :)

#

dont forget to ask for help in this thread now and then in #djs-help-v14 , so it doesnt get forgotten :)

fiery lily
uneven bison
#

TOKEN=

rustic meadow
#

@uneven bison add a ; after setToken

stone robin
rustic meadow
#

setToken(...);

fiery lily
#

not process.env.BOT_TOKEN

uneven bison
#

I have TOKEN

stone robin
#

yea he jsut set it to TOKEN

stone robin
fiery lily
#

don't put rest

uneven bison
#

I will try the semi colon.

rustic meadow
#

no it's exactly the issue

fiery lily
#

rest doesn't have function on .setToken

stone robin
fiery lily
#

rest.setToken is not exist,

rustic meadow
#
setToken(..)

(async function (){})
```this is being treated as```js
setToken(..)(async function (){})
``` basically calling setToken's result `setToken()()`
fiery lily
#

only rest constructor,

rustic meadow
#

adding a ; fixes it

stone robin
#

that one case where you need to use ; in js

uneven bison
#

it worked now I'm getting permission denied

stone robin
#

thern you bot doesnt have the right scope

rustic meadow
#

show the actual error, don't assume what it says

uneven bison
#

S[0]: 405: Method Not Allowed

rustic meadow
stone robin
#

yea

fiery lily
#

oop i have an replacement, bye now :)

rustic meadow
#

even js something ['a', 'b'] accesses something['b']

#
                    Routes.applicationGuildCommand(CLIENT_ID, process.env.GUILD_ID),
``` @uneven bison applicationGuildCommand`s`
uneven bison
#

Thanks

stone robin
#

๐Ÿ‘

uneven bison
#

The s makes the difference lmao.

stone robin
#

yea, and it makes sense *me: blind -> Ben: ๐Ÿ‘€ *

uneven bison
#

S[50001]: Missing Access

rustic meadow
uneven bison
#

Intents?

stone robin
rustic meadow
uneven bison
#

ohhhhhhhhhhhhhh

#

its in there wow

rustic meadow
#

you don't need to kick the bot, just reuse that link

uneven bison
#

NICE it works

#

Thanks guys.