Closed FrancimanLst closed 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
Thank you for the help, now i fixed! -Francesco
The problem persist on Heroku and i don't any idea on how to fix it there :/
im having the same error in heroku
@FrancimanLst @Princevikas Are you sure your Node.js version in Heroku is 16+?
@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"
}
}
Just add:
"engines": { "node": "16.9.0" }
it works on my Heroku :D
@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]: }
The "package.json" will like this:
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")
And it works smoothly :33
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 :/
@FrancimanLst Did you create Mongoose database and put the "mongo_URI" in config.json yet??
@KiyoshiKunCool Yes, if i start the bot locally it works fine, the problem is when i try to do it on Heroku
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
@FrancimanLst The config.json needs to be at the root directory of the project, at the same level index.js is
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!
When i try to run the command
node index.js
i get this error:I hope you can help me, Francesco.