#Enzyy bot.token undefined

1 messages ยท Page 1 of 1 (latest)

tardy cobalt
#

I don't see the execute function being called in that file?
(Pulled this into a thread to cut down on spam in the main channel ๐Ÿ™‚ )

tardy cobalt
#

so we need to see where the code is that calls that execute function

#

since thats the function getting passed the bot, and the code that thinks bot is undefined

vagrant tendon
#

I'm not so sure why it's bringing this error now that I'm using / commands, on my normal timeout.js command it worked just fine

tardy cobalt
#

try console.logging bot in your execute function, is it undefined?

vagrant tendon
#

tried console.log(bot) on my deploy-commands.js file, it doesn't say undefined

tardy cobalt
#

hmm, so personally I've never tried accessing the token off the DJS Client object, so unsure about how it gets set or whatever...
But if your bot variable is the client object, then thats good, it means the bot variable is being passed properly.

Not sure how to fix the 'original' DJS Client object token throwing undefined unfortunately...
Fortunately, easy fix is just pull in your token from your config file into that file
const { token } = require(/* path to config.json */)

#

does that solve the error in the meantime?

vagrant tendon
#

hey sorry was out for a sec

tardy cobalt
#

except your code you were doing bot.token??

vagrant tendon
tardy cobalt
#

which is what was erroring

vagrant tendon
tardy cobalt
#

yep, so import the token into that file and swap out bot.token with the imported token

#

to get your code working

vagrant tendon
#

Works now.. tysm heartcartoon

tardy cobalt
#

np

#

looking at the source code for DJS

#

looks like when you define your bot const bot = ... you can possibly do bot.token = <tokenhere> and that should mean that bot.token would work?
(in the code it's listed as a writable parameter)

#

the only time client.token is auto set is if you are using a .env file and the dotenv npm package and the token is called DISCORD_TOKEN in your .env file

#

but yea otherwise you can just import the token when and where you need it ๐Ÿคทโ€โ™‚๏ธ

vagrant tendon
#

I just removed bot. from bot.token & it worked just fine ๐Ÿ™‚

tardy cobalt
#

yep

vagrant tendon
#

Once again thank you very much for the help, appreciate it!

tardy cobalt
#

looking at the code, you need to actually assign the token to the bot object if you want it to be stored in the bot (or use dotenv and a .env file with a DISCORD_TOKEN value`

#

and np happy to help ๐Ÿ™‚

tardy cobalt
#

still learning myself so having to pick out errors in other peoples code helps me get my head around how things work more xD

vagrant tendon
#

if you wanna see how it the command looks like, I'm more than happy to show you