galnir / Master-Bot

A Discord music bot and dashboard with slash commands, playlist support, Spotify, music quiz, saved playlists, lyrics, gifs and more
MIT License
465 stars 372 forks source link

The bot doesn't start #625

Closed FrancimanLst closed 3 years ago

FrancimanLst commented 3 years ago

When i try to run the command node index.js i get this error:

C:\Users\Utente\Documents\Master-Bot-main>node index.js
internal/modules/cjs/loader.js:892
  throw err;
  ^

Error: Cannot find module 'timers/promises'
Require stack:
- C:\Users\Utente\Documents\Master-Bot-main\node_modules\@discordjs\rest\dist\lib\handlers\SequentialHandler.js
- C:\Users\Utente\Documents\Master-Bot-main\node_modules\@discordjs\rest\dist\lib\RequestManager.js
- C:\Users\Utente\Documents\Master-Bot-main\node_modules\@discordjs\rest\dist\index.js
- C:\Users\Utente\Documents\Master-Bot-main\index.js
←[90m    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:745:27)←[39m
←[90m    at Module.require (internal/modules/cjs/loader.js:961:19)←[39m
←[90m    at require (internal/modules/cjs/helpers.js:92:18)←[39m
    at Object.<anonymous> (C:\Users\Utente\Documents\Master-Bot-main\node_modules\←[4m@discordjs←[24m\rest\dist\lib\handlers\SequentialHandler.js:6:20)
←[90m    at Module._compile (internal/modules/cjs/loader.js:1072:14)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:937:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:778:12)←[39m
←[90m    at Module.require (internal/modules/cjs/loader.js:961:19)←[39m {
  code: ←[32m'MODULE_NOT_FOUND'←[39m,
  requireStack: [
    ←[32m'C:\\Users\\Utente\\Documents\\Master-Bot-main\\node_modules\\@discordjs\\rest\\dist\\lib\\handlers\\SequentialHandler.js'←[39m,
    ←[32m'C:\\Users\\Utente\\Documents\\Master-Bot-main\\node_modules\\@discordjs\\rest\\dist\\lib\\RequestManager.js'←[39m,
    ←[32m'C:\\Users\\Utente\\Documents\\Master-Bot-main\\node_modules\\@discordjs\\rest\\dist\\index.js'←[39m,
    ←[32m'C:\\Users\\Utente\\Documents\\Master-Bot-main\\index.js'←[39m
  ]
}

I hope you can help me, Francesco.

Bacon-Fixation commented 3 years ago

Howdy,

with the recent discord.js v13 changes the node and python versions are different

try with Node V16 https://nodejs.org/en/download/current/ Python 3 https://www.python.org/downloads/

then run npm ci --production again

i hope this helps

Much Love -Bacon

FrancimanLst commented 3 years ago

Thank you for the help, now i fixed! -Francesco

FrancimanLst commented 3 years ago

The problem persist on Heroku and i don't any idea on how to fix it there :/

Princevikas commented 3 years ago

im having the same error in heroku

galnir commented 3 years ago

@FrancimanLst @Princevikas Are you sure your Node.js version in Heroku is 16+?

FrancimanLst commented 3 years ago

@galnir I just tried to upgrade the node version to 16+ but it still giving me problem... Maybe i did something wrong, here is my package.json modified:

{
  "name": "master-bot",
  "version": "1.0.0",
  "description": "a discord music bot with guild , gifs and misc commands",
  "main": "index.js",
  "scripts": {
    "start": "node .",
    "test": "jest",
    "test:watch": "jest --watch",
    "pretest": "eslint --ignore-path .gitignore ."
  },
  "author": "Nir Gal",
  "license": "ISC",
  "dependencies": {
    "@discordjs/builders": "^0.5.0",
    "@discordjs/opus": "^0.6.0",
    "@discordjs/rest": "^0.1.0-canary.0",
    "@discordjs/voice": "^0.6.0",
    "@vitalets/google-translate-api": "^7.0.0",
    "cheerio": "^1.0.0-rc.10",
    "discord-api-types": "^0.22.0",
    "discord.js": "^13.1.0",
    "discord.js-pages": "^1.3.0",
    "ffmpeg": "0.0.4",
    "ffmpeg-static": "^4.4.0",
    "iso-639-1": "^2.1.9",
    "libsodium-wrappers": "^0.7.9",
    "mongoose": "^5.13.5",
    "spotify-url-info": "^2.2.3",
    "youtube-dl-exec": "^1.2.4",
    "youtube-sr": "^4.1.7",
    "ytdl-core": "^4.9.1"
  },
  "devDependencies": {
    "babel-eslint": "^10.1.0",
    "eslint": "^5.16.0",
    "eslint-plugin-jest": "^24.4.0",
    "jest": "^27.1.1",
    "nodemon": "^1.19.4",
    "prettier": "^1.19.1"
  },
  "engines": {
    "node": "16.x",
    "npm": ">=6.0.0"
  }
}
kiyoshikuncool commented 3 years ago

Just add:

"engines": { "node": "16.9.0" }

it works on my Heroku :D

FrancimanLst commented 3 years ago

@KiyoshiKunCool Ok that worked, thank you. But now for some reasons Heroku doesn't find anymore my config.json....

2021-09-18T17:22:50.342988+00:00 app[worker.1]: node:internal/modules/cjs/loader:936
2021-09-18T17:22:50.343005+00:00 app[worker.1]:   throw err;
2021-09-18T17:22:50.343005+00:00 app[worker.1]:   ^
2021-09-18T17:22:50.343005+00:00 app[worker.1]: 
2021-09-18T17:22:50.343006+00:00 app[worker.1]: Error: Cannot find module './config.json'
2021-09-18T17:22:50.343006+00:00 app[worker.1]: Require stack:
2021-09-18T17:22:50.343006+00:00 app[worker.1]: - /app/index.js
2021-09-18T17:22:50.343007+00:00 app[worker.1]:     at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
2021-09-18T17:22:50.343007+00:00 app[worker.1]:     at Function.Module._load (node:internal/modules/cjs/loader:778:27)
2021-09-18T17:22:50.343007+00:00 app[worker.1]:     at Module.require (node:internal/modules/cjs/loader:1005:19)
2021-09-18T17:22:50.343008+00:00 app[worker.1]:     at require (node:internal/modules/cjs/helpers:94:18)
2021-09-18T17:22:50.343008+00:00 app[worker.1]:     at Object.<anonymous> (/app/index.js:5:41)
2021-09-18T17:22:50.343008+00:00 app[worker.1]:     at Module._compile (node:internal/modules/cjs/loader:1101:14)
2021-09-18T17:22:50.343008+00:00 app[worker.1]:     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
2021-09-18T17:22:50.343009+00:00 app[worker.1]:     at Module.load (node:internal/modules/cjs/loader:981:32)
2021-09-18T17:22:50.343009+00:00 app[worker.1]:     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2021-09-18T17:22:50.343009+00:00 app[worker.1]:     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12) {
2021-09-18T17:22:50.343010+00:00 app[worker.1]:   code: 'MODULE_NOT_FOUND',
2021-09-18T17:22:50.343010+00:00 app[worker.1]:   requireStack: [ '/app/index.js' ]
2021-09-18T17:22:50.343010+00:00 app[worker.1]: }
kiyoshikuncool commented 3 years ago

The "package.json" will like this: Ảnh chụp màn hình 2021-09-19 083513

And I set config the "buildpacks" like this: (Cmd: "heroku buildpacks:set https://github.com/heroku/heroku-buildpack-nodejs#latest -a your-app" | Change "your-app" to your app name like "mastet-bot")

Ảnh chụp màn hình 2021-09-19 083135

And it works smoothly :33

KiyoshiKunCool

FrancimanLst commented 3 years ago

I did all that again and it leaves me again with the error message 'Cannot find module './config.json'

Maybe it's a problem about my index.js file, idk Here my index.js:

const fs = require('fs');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { Client, Collection, Intents } = require('discord.js');
const { token, mongo_URI, client_id } = require('./config.json');
const mongoose = require('mongoose');

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

const client = new Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MEMBERS,
    Intents.FLAGS.GUILD_MESSAGES,
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_VOICE_STATES
  ]
});

client.commands = new Collection();
const commands = [];

const commandFiles = fs
  .readdirSync('./commands')
  .map(folder =>
    fs
      .readdirSync(`./commands/${folder}`)
      .filter(file => file.endsWith('.js'))
      .map(file => `./commands/${folder}/${file}`)
  )
  .flat();

for (const file of commandFiles) {
  const command = require(`${file}`);
  if (Object.keys(command).length === 0) continue;
  commands.push(command.data.toJSON());
  client.commands.set(command.data.name, command);
}

(async () => {
  try {
    console.log('Started refreshing application (/) commands.');

    await rest.put(Routes.applicationCommands(client_id), {
      body: commands
    });

    console.log('Successfully reloaded application (/) commands.');
  } catch (error) {
    console.error(error);
  }
})();

const eventFiles = fs
  .readdirSync('./events')
  .filter(file => file.endsWith('.js'));

for (const file of eventFiles) {
  const event = require(`./events/${file}`);
  if (event.once) {
    client.once(event.name, (...args) => event.execute(...args, client));
  } else {
    client.on(event.name, (...args) => event.execute(...args, client));
  }
}

client.once('ready', () => {
  client.playerManager = new Map();
  client.triviaManager = new Map();
  client.guildData = new Collection();
  client.user.setActivity('/', { type: 'WATCHING' });
  mongoose
    .connect(encodeURI(mongo_URI), {
      useNewUrlParser: true,
      useUnifiedTopology: true
    })
    .then(() => {
      console.log('Mongo is ready');
    })
    .catch(console.error);

  console.log('Ready!');
});

client.login(token);

I also tried to change './config.json' with '../config.json' but gave me same error :/

kiyoshikuncool commented 3 years ago

@FrancimanLst Did you create Mongoose database and put the "mongo_URI" in config.json yet??

FrancimanLst commented 3 years ago

@KiyoshiKunCool Yes, if i start the bot locally it works fine, the problem is when i try to do it on Heroku

MrUnstable commented 3 years ago

Tried to recreate this whole thing and basically what fixed it for me is forking a private copy of Master-Bot , adding config.json and Procfile to private fork and turning auto deployment in Heroku (main branch) make sure both config and Procfile are also uploaded in main branch more info in #490

galnir commented 3 years ago

@FrancimanLst The config.json needs to be at the root directory of the project, at the same level index.js is

FrancimanLst commented 3 years ago

I'm stupid, i didn't add config.json to the fork on github... Sorry guys for bothering you and thanks for the help! Now it works and that's the worth part!