Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Stentorian

Discord.js Issues

Recommended Posts

Posted · Original PosterOP

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

CPU: Intel Xeon E5-2667 v3 @ 3.20Ghz (8 core)

RAM: 12GB Server Memory

Mobo: Blade ShadowM

GPU: Zotac NVIDIA GeForce GTX 1080 4GB

SSD: 256GB SSD

 

Mouse: Logitech M150

Keyboard: Stoga MK6

Current Laptop:

Spoiler

CPU: Intel Core i3-8130U @ 2.2Ghz (3.4Ghz turbo)

Graphics: Intel UHD Graphics

Mobo: Acer A315-53-33DZ

RAM: 4GB DDR4

SSD: 256GB SSD

Other Gear:

Spoiler

Phone: iPhone 6 - Silver 16GB

Microphone: Tonor Desk Microphone

Headphones: Kotion Each G2000

Assistant: Amazon Echo 1st Gen - Black

Self Promo Links:

 

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
Link to post
Share on other sites
Posted · Original PosterOP
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

CPU: Intel Xeon E5-2667 v3 @ 3.20Ghz (8 core)

RAM: 12GB Server Memory

Mobo: Blade ShadowM

GPU: Zotac NVIDIA GeForce GTX 1080 4GB

SSD: 256GB SSD

 

Mouse: Logitech M150

Keyboard: Stoga MK6

Current Laptop:

Spoiler

CPU: Intel Core i3-8130U @ 2.2Ghz (3.4Ghz turbo)

Graphics: Intel UHD Graphics

Mobo: Acer A315-53-33DZ

RAM: 4GB DDR4

SSD: 256GB SSD

Other Gear:

Spoiler

Phone: iPhone 6 - Silver 16GB

Microphone: Tonor Desk Microphone

Headphones: Kotion Each G2000

Assistant: Amazon Echo 1st Gen - Black

Self Promo Links:

 

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
Link to post
Share on other sites
Posted · Original PosterOP
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

CPU: Intel Xeon E5-2667 v3 @ 3.20Ghz (8 core)

RAM: 12GB Server Memory

Mobo: Blade ShadowM

GPU: Zotac NVIDIA GeForce GTX 1080 4GB

SSD: 256GB SSD

 

Mouse: Logitech M150

Keyboard: Stoga MK6

Current Laptop:

Spoiler

CPU: Intel Core i3-8130U @ 2.2Ghz (3.4Ghz turbo)

Graphics: Intel UHD Graphics

Mobo: Acer A315-53-33DZ

RAM: 4GB DDR4

SSD: 256GB SSD

Other Gear:

Spoiler

Phone: iPhone 6 - Silver 16GB

Microphone: Tonor Desk Microphone

Headphones: Kotion Each G2000

Assistant: Amazon Echo 1st Gen - Black

Self Promo Links:

 

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

Buy VPN

×