Androz2091 / discord-giveaways

🎉 Complete framework to facilitate the creation of giveaways using discord.js
https://discord-giveaways.js.org
MIT License
334 stars 127 forks source link

Error: cannot read property 'forEach' of undefined. #239

Closed FC5570 closed 3 years ago

FC5570 commented 3 years ago

Hello, im getting an error from this package, (/src/Manager.js:448), heres the error: unknown

If you need any more info, please mention me. Thanks.

Nico105 commented 3 years ago

@FC5570 which DB are you using?

Dragonizedpizza commented 3 years ago

@FC5570 hello comrade Could you show us your code, along with which DB you're using, as Nico said?

FC5570 commented 3 years ago

I use quickmongo (https://npmjs.com/package/quickmongo), something like quick.db but stores data to mongodb.

Also, after taking a look at the code of this package, it looks like this error occured because I don't have a getAllGiveaways() function.

Nico105 commented 3 years ago

https://github.com/Androz2091/discord-giveaways/blob/develop/examples/custom-databases/quickmongo.js Add it like that and take note to add the line 65 and 70 part

FC5570 commented 3 years ago

Alright, I'll try that, thanks

FC5570 commented 3 years ago

I still get an error, this is a weird one, it says it cant read property 'fetch' of undefined in getAllGiveaways() function, this is my code: https://sourceb.in/B7oXNRt1Eq, the error is from the line where I return the fetched giveaways in getAllGiveaways() function, line 3 in the above code

Dragonizedpizza commented 3 years ago

@FC5570 could you show us your database initialization?

FC5570 commented 3 years ago

@FC5570 could you show us your database initialization?

const { Database } = require("quickmongo"); this.db = new Database('uri'); this.db.on('ready', async () => { if (!Array.isArray(await this.db.get('giveaways'))) await this.db.set('giveaways', []); this.giveawaysManager._init(); });

Nico105 commented 3 years ago

Could you try moving the class extends and db creation (assign to const) outside of your client extending, so like this https://github.com/Androz2091/discord-giveaways/issues/190

FC5570 commented 3 years ago

Yea that worked, thanks