#Debian Server will not start the bot

20 messages · Page 1 of 1 (latest)

wind marlin
#

I have a server for my discord bots, to host my bots i use the package pm2.

When I hosted the first bot everything worked fine, but when I uploaded the 2nd bot, it no longer found the ./handlers folder, when I then tried further commands with pm2 the first bot also worked at some point (after 5 days of running time ) no longer. What is the reason and how can I fix this error? (The folder is in the same folder from which it is also called)

outer quiver
onyx dew
#

Tried to use readdir on ./handlers, but the path doesn’t exist

#

FS uses the current working directory for relative paths, not the folder of the file it’s called in

#

You should have the terminal set in the same directory as the folder that contains the package.json file, esp when running npm commands

wind marlin
# outer quiver Hard to say without the rest of the error Do `pm2 log —lines 400` or so, notic...

Code from index.js


const { EmbedBuilder, Client, GatewayIntentBits, Partials, Collection } = require('discord.js');
const { token } = require("./config.json")
const client = new Client({
    intents: [
        
GatewayIntentBits.GuildScheduledEvents,

        GatewayIntentBits.Guilds, 
        GatewayIntentBits.GuildMessages, 
        GatewayIntentBits.GuildPresences, 
        GatewayIntentBits.GuildMessageReactions, 
        
GatewayIntentBits.AutoModerationConfiguration,
        
GatewayIntentBits.AutoModerationExecution,
        GatewayIntentBits.DirectMessages,
        GatewayIntentBits.MessageContent,
        GatewayIntentBits.GuildMembers
    ], 
    partials: [Partials.Channel, Partials.Message, Partials.User, Partials.GuildMember, Partials.Reaction] 
});

const fs = require('fs');
const config = require('./config.json');

client.commands = new Collection()
client.aliases = new Collection()
client.slashCommands = new Collection();
client.buttons = new Collection();
client.modals = new Collection();
client.selectMenus = new Collection();
client.prefix = config.prefix;

module.exports = client;


fs.readdirSync('./handlers').forEach((handler) => {
  require(`./handlers/${handler}`)(client)
});


client.login(token)```
#

it only stopped working after I uploaded the 2nd bot and tried to host it as well

wind marlin
#

and not

pm2 start ./Ge747-Bot/index.js
outer quiver
#

You wanna cd into each like, bot folder

#

Then start it

outer quiver
wind marlin
outer quiver
wind marlin
wind marlin
# outer quiver And what do the logs say

I have fixed this with this new index:

const { EmbedBuilder, Client, GatewayIntentBits, Partials, Collection } = require('discord.js');
const { token } = require("./config.json")
const client = new Client({
    intents: [
        
GatewayIntentBits.GuildScheduledEvents,

        GatewayIntentBits.Guilds, 
        GatewayIntentBits.GuildMessages, 
        GatewayIntentBits.GuildPresences, 
        GatewayIntentBits.GuildMessageReactions, 
        
GatewayIntentBits.AutoModerationConfiguration,
        
GatewayIntentBits.AutoModerationExecution,
        GatewayIntentBits.DirectMessages,
        GatewayIntentBits.MessageContent,
        GatewayIntentBits.GuildMembers
    ], 
    partials: [Partials.Channel, Partials.Message, Partials.User, Partials.GuildMember, Partials.Reaction] 
});

const fs = require('fs');
const config = require('./config.json');
//require('dotenv').config() // remove this line if you are using replit

client.commands = new Collection()
client.aliases = new Collection()
client.slashCommands = new Collection();
client.buttons = new Collection();
client.modals = new Collection();
client.selectMenus = new Collection();
client.prefix = config.prefix;

module.exports = client;


fs.readdirSync('./Ge747-Bot/handlers').forEach((handler) => {
  require(`./Ge747-Bot/handlers/${handler}`)(client)
});


client.login(token)```

but I get this new error
limber flame
# wind marlin I have fixed this with this new index: ```javascript const { EmbedBuilder, Clien...

Assuming you followed what they said and you CD into the same folder index.js is, you need to update all your dir strings to remove 'Ge747-Bot'. For example your

fs.readdirSync('./Ge747-Bot/handlers').forEach((handler) => {
  require(`./Ge747-Bot/handlers/${handler}`)(client)
});

should now be

fs.readdirSync('./handlers').forEach((handler) => {
  require(`./handlers/${handler}`)(client)
});

Again this is assuming you are IN the 'Ge747-Bot' folder when starting the bot. If you have any other files referencing the 'Ge747-Bot' folder in its path, it will throw an error now.