Closed Dragonizedpizza closed 3 years ago
What exactly is the line that causes the error?
@Nico105 (node:12040) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'giveaways' of undefined at Object.run (C:\Users\akyra\Desktop\Bots\DragonNight\bot\commands\giveaways\gstart.js:19:37)
line 19
database = mongoose.model('database', botDB)
this should have a const
. idk if that is relevant
does console.log(client.giveawaysManager)
have any value in your cmd?
does
console.log(client.giveawaysManager)
have any value in your cmd?
I've evalled console.log(message.client.giveawaysManager)
and got undefined.
So it could be that you pass the manager the wrong client/not the actual client. Do you extend the default discord.js client?
try removing the const client = require('@root/index.js');
change module.exports = async () => {
to module.exports = async (client) => {
And in your index do require('theManagerFile')(client)
(node:19832) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'find' of undefined
async getAllGiveaways() {
return await database.giveaways.find({});
}```
giveaways: {```
It seems giveaways is undefined?
the thing is giveaway
is described as an object in your schema, but you cannot acces it database.giveaways
like that from your model because its data and you don't access it like that
The solution is probably that you just make a seperate schema and seperate model for your normal data
But I'm using the free MongoDB plan, which times out at 1 connection...
nah not connections, just seperate collections
const botData = new mongoose.Schema({
blacklists: {
uid: String,
sid: String
}
})
const botDB = mongoose.model('database', botData);
botDB.create({blacklists: { uid: 'test', sid: 'test' }})
You put this somewhere and change the giveaway stuff back to https://github.com/Androz2091/discord-giveaways/blob/develop/examples/custom-databases/mongoose.js
ah. thanks!
^ file used to initialize giveaways client
const database = require('./bot/utilities/schema.js')
^ code used to initialize client