Skip to content
← Back to Community
Error: Cannot find module './commands/${file}'
Profile icon
CodyMarkix

So I'm currently making a Discord bot and when I tried to turn it on, the console showed this error and it didn't turn on.

Error: Cannot find module './commands/${file}'
Require stack:

  • /home/runner/TerraBot/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
    at Function.Module._load (internal/modules/cjs/loader.js:841:27)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at /home/runner/TerraBot/index.js:23:19
    at Script.runInContext (vm.js:130:18)
    at Object. (/run_dir/interp.js:209:20)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)

And I don't really know how to fix this.
Can someone help me, please?

Voters
Profile icon
SIFAT69
Profile icon
CodyMarkix
Comments
hotnewtop
Profile icon
Coder100

wher repl

Profile icon
[deleted]

Hi @Hplr63 I saw your repl and your bot's token is in it. Repls are public and anyone can view it. I would suggest you to go to https://docs.repl.it/repls/secret-keys and hide your token. And regenerate it or anyone can use it.

Profile icon
CodyMarkix

@Zapdos Thanks a lot! I noticed it after posting it and decided to hide it in an .env file!

Profile icon
KHZ

@Hplr63 shouldn't the command be

`./commands/${file}`

instead of './commands/${file}'

Profile icon
KHZ

@KHZ so that the name of the file changes every time the loop executes. Right now the name of the file remains ${file} and it is not getting formatted as to format a string instead of commas ' back ticks(`) should be used .

Profile icon
CodyMarkix

@KHZ lemme try that. I'll give you an update
Update: It worked! Thanks for answering!
I'm a total newbie when it comes to Discord.js

Profile icon
KHZ

@Hplr63 No worries I don't know js that much myself.