Jump to content

Discord.js Issues

Stentorian
Go to solution Solved by Jisagi,

I'm not sure why you put the eventloading inside an async block. Since it's the bot.on function inside that block which fails, it might be a good idea to make this block sync. Then you can also kick promisify. fs.readdir also has a sync version, so it would then look something like shown below. Worth trying I guess.

 

// Old
(async () => {
    let events = await readdir("./main/events/");
    events.forEach(file => {
        const name = file.slice(0, -3);
        const event = require(`./main/events/${file}`);
        //Stole this line as it was so much better than what I had:
        bot.on(name, event.bind(null, bot));
    });
})();

// New
const { readdirSync } = require('fs');
let events = readdirSync('./main/events/');
events.forEach(file => {
  const name = file.slice(0, -3);
  const event = require(`./main/events/${file}`);
  bot.on(name, event.bind(null, bot));
});

 

BTW, you have 2 message event handlers in line 85 and 114. You already use an eventloader structure, so why no moving it there as well?

Hey, 

 

I am currently in progress of making a public Discord Bot and recently I changed up the command handler for a new updated one that helps me code things like a help command quicker. 

Since I made the command handler, the event handler has stopped working and I don't know why. I have provided links to the relevant files plus a screenshot of my events folder to show that all the events that are in the folder are valid Discord.js events.

 

App.js file: https://hasteb.in/coqofihu.js

Error: https://hasteb.in/wamofere.php

Events Folder: http://prntscr.com/prij7u

 

If you need any more files then feel free to ask and I can provide them.

 

Any help would be awesome!

 

Many Thanks, 

Ben

Current PC: 

Spoiler

Motherboard: MSI Z390-A PRO

CPU: Intel Core i7-9700K @ 3.60GHz

Memory: 32GB (4x8GB) Corsair Vengeance 

Graphics Card: NVIDIA GeForce RTX 3060 Ti

Boot: Crucial P2 500GB (M.2)

SSD: Crucial BX500 1TB

HDD: Seagate ST2000DM001 2TB

HDD: Seagate Barracuda 4TB

PSU: Gigabyte P750GM 750W

Case: IONZ KZ10

Current Laptop:

Spoiler

Name: Lenovo ThinkBook 14 20SL003JUK

CPU: Intel i7-1065G7 @ 3GHz

Graphics: Intel Iris Graphics

RAM: 16GB DDR4 @ 2667MHz

SSD: 480GB Western Digital M.2

Secondary SSD: 240GB Adata SATA

Other Gear:

Spoiler

Phone: Google Pixel 6 (128GB)

Headphones: Steelseries Arctis 3

Microphone: Blue Snowball Ice

Speakers: Creative T100

Link to comment
Share on other sites

Link to post
Share on other sites

Judging from the error with async, I'd say it's an outdated nodejs version, maybe 6 or lower. Try updating it to LTS (v12.x) or Latest (v13.x). You can check your nodejs version by typing "node -v" into the (windows) console.

If it's not that, check if you use the latest discord.js version which should be 11.5.1 (or the master branch).

Edited by Jisagi

Gaming Rig: Ryzen 9 5950x | 2x16GB DDR4 3200MHz | XFX Reference 6800 XT | MSI Unify X570 | Corsair MP600 2TB, Samsung 850 Evo 500GB | bequiet 850W Straight Power 11

Server: Ryzen 5 3600 | 4x32GB DDR4 ECC 2400MHz | Asrock Rack X470D4U | Samsung EVO Plus 250GB, 6x Seagate Exos 8TB, Samsung 850 Pro 1TB | bequiet 550W Straight Power 11

Link to comment
Share on other sites

Link to post
Share on other sites

On 11/3/2019 at 11:42 AM, Jisagi said:

Judging from the error with async, I'd say it's an outdated nodejs version, maybe 6 or lower. Try updating it to LTS (v12.x) or Latest (v13.x). You can check your nodejs version by typing "node -v" into the (windows) console.

If it's not that, check if you use the latest discord.js version which should be 11.5.1 (or the master branch).

Updated note to 12.13.0 and updated all my packages (including Discord.js) to the latest release and the error still occurs. Also apologies for the late response. 

Current PC: 

Spoiler

Motherboard: MSI Z390-A PRO

CPU: Intel Core i7-9700K @ 3.60GHz

Memory: 32GB (4x8GB) Corsair Vengeance 

Graphics Card: NVIDIA GeForce RTX 3060 Ti

Boot: Crucial P2 500GB (M.2)

SSD: Crucial BX500 1TB

HDD: Seagate ST2000DM001 2TB

HDD: Seagate Barracuda 4TB

PSU: Gigabyte P750GM 750W

Case: IONZ KZ10

Current Laptop:

Spoiler

Name: Lenovo ThinkBook 14 20SL003JUK

CPU: Intel i7-1065G7 @ 3GHz

Graphics: Intel Iris Graphics

RAM: 16GB DDR4 @ 2667MHz

SSD: 480GB Western Digital M.2

Secondary SSD: 240GB Adata SATA

Other Gear:

Spoiler

Phone: Google Pixel 6 (128GB)

Headphones: Steelseries Arctis 3

Microphone: Blue Snowball Ice

Speakers: Creative T100

Link to comment
Share on other sites

Link to post
Share on other sites

I'm not sure why you put the eventloading inside an async block. Since it's the bot.on function inside that block which fails, it might be a good idea to make this block sync. Then you can also kick promisify. fs.readdir also has a sync version, so it would then look something like shown below. Worth trying I guess.

 

// Old
(async () => {
    let events = await readdir("./main/events/");
    events.forEach(file => {
        const name = file.slice(0, -3);
        const event = require(`./main/events/${file}`);
        //Stole this line as it was so much better than what I had:
        bot.on(name, event.bind(null, bot));
    });
})();

// New
const { readdirSync } = require('fs');
let events = readdirSync('./main/events/');
events.forEach(file => {
  const name = file.slice(0, -3);
  const event = require(`./main/events/${file}`);
  bot.on(name, event.bind(null, bot));
});

 

BTW, you have 2 message event handlers in line 85 and 114. You already use an eventloader structure, so why no moving it there as well?

Edited by Jisagi

Gaming Rig: Ryzen 9 5950x | 2x16GB DDR4 3200MHz | XFX Reference 6800 XT | MSI Unify X570 | Corsair MP600 2TB, Samsung 850 Evo 500GB | bequiet 850W Straight Power 11

Server: Ryzen 5 3600 | 4x32GB DDR4 ECC 2400MHz | Asrock Rack X470D4U | Samsung EVO Plus 250GB, 6x Seagate Exos 8TB, Samsung 850 Pro 1TB | bequiet 550W Straight Power 11

Link to comment
Share on other sites

Link to post
Share on other sites

On 11/8/2019 at 10:27 PM, Jisagi said:

I'm not sure why you put the eventloading inside an async block. Since it's the bot.on function inside that block which fails, it might be a good idea to make this block sync. Then you can also kick promisify. fs.readdir also has a sync version, so it would then look something like shown below. Worth trying I guess.

 


// Old
(async () => {
    let events = await readdir("./main/events/");
    events.forEach(file => {
        const name = file.slice(0, -3);
        const event = require(`./main/events/${file}`);
        //Stole this line as it was so much better than what I had:
        bot.on(name, event.bind(null, bot));
    });
})();

// New
const { readdirSync } = require('fs');
let events = readdirSync('./main/events/');
events.forEach(file => {
  const name = file.slice(0, -3);
  const event = require(`./main/events/${file}`);
  bot.on(name, event.bind(null, bot));
});

 

BTW, you have 2 message event handlers in line 85 and 114. You already use an eventloader structure, so why no moving it there as well?

It worked thanks. Really appreciate the help!

Current PC: 

Spoiler

Motherboard: MSI Z390-A PRO

CPU: Intel Core i7-9700K @ 3.60GHz

Memory: 32GB (4x8GB) Corsair Vengeance 

Graphics Card: NVIDIA GeForce RTX 3060 Ti

Boot: Crucial P2 500GB (M.2)

SSD: Crucial BX500 1TB

HDD: Seagate ST2000DM001 2TB

HDD: Seagate Barracuda 4TB

PSU: Gigabyte P750GM 750W

Case: IONZ KZ10

Current Laptop:

Spoiler

Name: Lenovo ThinkBook 14 20SL003JUK

CPU: Intel i7-1065G7 @ 3GHz

Graphics: Intel Iris Graphics

RAM: 16GB DDR4 @ 2667MHz

SSD: 480GB Western Digital M.2

Secondary SSD: 240GB Adata SATA

Other Gear:

Spoiler

Phone: Google Pixel 6 (128GB)

Headphones: Steelseries Arctis 3

Microphone: Blue Snowball Ice

Speakers: Creative T100

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×