#Erikost3 - TypeError rest.setToken is not a function
1 messages ยท Page 1 of 1 (latest)
Okay
let me take a look :)
I'm pretty new to js so yeah that's why this problem is probably nothing big lmao
but ya imported @discordjs/rest right?
npm i @discordjs/rest
whats written in your package.json ?
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"
}
}
okay, yea its imported
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);
console.log(REST)
but that's properly something like [class de extends EventEmitter]
yes
but you could instead do the console.log() of your rest constant like console.log(rest) directly after creating it
that should look simmalar to this
yea
yea, functions are nor listed there
now this is confusing
https://discord.js.org/#/docs/rest/stable/general/welcome also the doc is down
no
oh
just that part of the documentation
nice
most likely null
and?
wtf message [Function: setToken]
so the funcction exists
oh, the ... s
huh?
do you have a .env file? DONT SHARE THE TOKEN
yes
and your token variable is exacctly called TOKEN=xyz?
TOKE? not TOKEN?
okay :)
if you cconsole log console.log(process.env.TOKEN) do you get your token in the cconsole
ahh okay :)
yep
hmm
okay?
I feel like there is something im missing on this line rest.setToken(process.env.TOKEN)
hold up imma ask my other friend
okay :)
https://www.npmjs.com/package/@discordjs/rest lul discordjs is using a deprecated package xD
so this will not be the way much longer like its looking, but still it should work for you
still looks weird
so the tutorial im using is shit dam
thats the official Tutorial https://discordjs.guide/interactions/registering-slash-commands.html#registering-slash-commands****
oh yeah
uhm but this works for u and not for me, then it means my package is wrong???
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"
}
}
yeah same version omg
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)
thank you for trying tho ๐
np :)
dont forget to ask for help in this thread now and then in #djs-help-v14 , so it doesnt get forgotten :)
what variable did you put to the .env?
TOKEN=
@uneven bison add a ; after setToken
his sourcecode ๐
setToken(...);
I have TOKEN
yea he jsut set it to TOKEN
shouldnt make a diffrence though
don't put rest
I will try the semi colon.
no it's exactly the issue
rest doesn't have function on .setToken
okay?
rest.setToken is not exist,
setToken(..)
(async function (){})
```this is being treated as```js
setToken(..)(async function (){})
``` basically calling setToken's result `setToken()()`
only rest constructor,
adding a ; fixes it
ohh, true
that one case where you need to use ; in js
it worked now I'm getting permission denied
thern you bot doesnt have the right scope
show the actual error, don't assume what it says
S[0]: 405: Method Not Allowed
you need to be careful using iifes and array literals
yea
oop i have an replacement, bye now :)
even js something ['a', 'b'] accesses something['b']
Routes.applicationGuildCommand(CLIENT_ID, process.env.GUILD_ID),
``` @uneven bison applicationGuildCommand`s`
Thanks
๐
The s makes the difference lmao.
yea, and it makes sense *me: blind -> Ben: ๐ *
S[50001]: Missing Access
add the scopes #769862166131245066
Intents?
no, scopes, <#769862166131245066 message>
also i recommend you follow the https://discordjs.guide/interactions/registering-slash-commands.html#guild-commands's approach, use a separate script instead of using it alongside your bot
you don't need to kick the bot, just reuse that link