KagChi/noteblock

could not start on replit

fanesz opened this issue · 19 comments

i can't run in replit, it always says [Symbol(code)]: 'TOKEN_INVALID']
because i can't rename .env.scheme to .env
how to solve it?

replit introduce new way to fill .env file, its now on environtment tab

i just did that, but it still show this

[2021-10-12T14:07:38.291] [INFO] NOTEBLOCK - [REPLIT ENVIRONMENT DETECTED] [STARTING WEBSERVER]
/home/runner/noteblock-2/node_modules/discord.js/src/client/Client.js:228
    if (!token || typeof token !== 'string') throw new Error('TOKEN_INVALID');
                                                   ^

Error [TOKEN_INVALID]: An invalid token was provided.
    at NoteClient.login (/home/runner/noteblock-2/node_modules/discord.js/src/client/Client.js:228:52)
    at NoteClient.initialize (/home/runner/noteblock-2/src/Struct/NoteClient.js:75:10)
    at Object.<anonymous> (/home/runner/noteblock-2/src/index.js:6:8)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at initialize (/home/runner/noteblock-2/src/main.js:25:12) {
  [Symbol(code)]: 'TOKEN_INVALID'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! noteblock@1.3.0 start: `bash start.sh`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the noteblock@1.3.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2021-10-12T14_07_39_392Z-debug.log
exit status 1

what i did :

  1. import from github
  2. input owner id at index.js
  3. make .env on environtment tab
  4. run

does it log your token if do console.log(process.env.DISCORD_TOKEN) ?, aslo dont copy the client secret one

it says :

console.log(process.env.DISCORD_TOKEN)
bash: syntax error near unexpected token `process.env.DISCORD_TOKEN'

in your main.js file duh, basic js.

sorry im new, i try to put console.log(process.env.DISCORD_TOKEN) in src/main.js but still says the same error (i've tried put it at the first line, middle line, and last line)

does it log your token

no, i didn't see any token when i run with that thing in my main.js
still show same error

also i've try self hosting it, and work perfectly. So i think the problem is with replit.

also i've try self hosting it, and work perfectly. So i think the problem is with replit.

Maybe you wrongly place the cofiguration in environment

i just host it at HEROKU.com and work perfectly,
but i still want host it at replit because heroku have limit usage.

is that any command for .replit file to read and run inside the code folder? so i can bash start.sh along with .env file in the same folder?
like : (inside .replit)

cd noteblock
run="npm run"

or maybe can i move .env file inside any folder and main.js still can read it?

image
are you inputed environment like this?

yes, i input :
key -> .env
value -> DISCORD_TOKEN=xxxx

SOLVED

so i just do npm install after cloning, then make .env with the things inside src folder
then in main.js
i change from :
require('dotenv').config();
to

const path = require('path')
require('dotenv').config({ path: path.resolve(__dirname, '.env') })

and it work prefectly ^^

thanks for resolving, current issue. gonna add to the code soon

THis still doesn't work, please help, I'm a bit rusty to this.
I did everything you guys said and I got this error:

`[2022-06-17T07:42:45.419] [INFO] NOTEBLOCK - [REPLIT ENVIRONMENT DETECTED] [STARTING WEBSERVER]
/home/runner/noteblock/node_modules/discord.js/src/client/Client.js:237
if (!token || typeof token !== 'string') throw new Error('TOKEN_INVALID');
^

Error [TOKEN_INVALID]: An invalid token was provided.
 npm start

noteblock@1.3.0 start /home/runner/noteblock
bash start.sh

npm WARN lifecycle The node binary used for scripts is /usr/bin/node but npm is using /home/runner/noteblock/node_modules/node/bin/node itself. Use the --scripts-prepend-node-path option to include the path for the node binary npm was executed with.

node@16.14.2 preinstall /home/runner/noteblock/node_modules/node
node installArchSpecificPackage

  • node-linux-x64@16.14.2
    added 1 package in 8.909s
    found 0 vulnerabilities

  • node@16.14.2
    removed 1 package, updated 1 package and audited 210 packages in 26.59s

65 packages are looking for funding
run npm fund for details

found 0 vulnerabilities

[2022-06-17T07:43:21.975] [INFO] NOTEBLOCK - [REPLIT ENVIRONMENT DETECTED] [STARTING WEBSERVER]
/home/runner/noteblock/node_modules/discord.js/src/client/Client.js:237
if (!token || typeof token !== 'string') throw new Error('TOKEN_INVALID');
^

Error [TOKEN_INVALID]: An invalid token was provided.
at NoteClient.login (/home/runner/noteblock/node_modules/discord.js/src/client/Client.js:237:52)
at NoteClient.initialize (/home/runner/noteblock/src/Struct/NoteClient.js:75:10)
at Object. (/home/runner/noteblock/src/index.js:7:8)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at initialize (/home/runner/noteblock/src/main.js:26:12) {
[Symbol(code)]: 'TOKEN_INVALID'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! noteblock@1.3.0 start: bash start.sh
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the noteblock@1.3.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2022-06-17T07_43_24_237Z-debug.log
exit status 1`

yes, i input : key -> .env value -> DISCORD_TOKEN=xxxx

Nope, you did it wrong,
This is what should be (according to this repo)
key=DISCORD_TOKEN,
value=[insert_your_bot_token_here]

yes, i input : key -> .env value -> DISCORD_TOKEN=xxxx

Nope, you did it wrong, This is what should be (according to this repo) key=DISCORD_TOKEN, value=****

this is not valid.

env should be
DISCORD_TOKEN=TOKEN
DISCORD_TOKEN is your key, and token is your value.

I'm talking about Replit Secrets
This 👇
image