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 when using custom DB #237

Closed KingCh1ll closed 3 years ago

KingCh1ll commented 3 years ago

I just came across the npm package today. I set it up with MongoDB and made a test command for it. When the giveaway ended, instead of picking a winner it gave me this error:

(node:22344) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received type 
boolean (false)

Anyone know why this is happening?

Nico105 commented 3 years ago

What node version do you use? Does it happen without mongoose=default db?

KingCh1ll commented 3 years ago

Hi! I use node 14.15.5. I'm using the package QuickMongo.

Nico105 commented 3 years ago

Okay, still, does it happen if you comment your custom DB manager out? so we can check if it's because of quickmongo and was this only for 1 giveaway or have you started some more and did it happen there too?

KingCh1ll commented 3 years ago

Quick Question before I answer yours; Would it matter if my mongoose version is 5.11.15?

KingCh1ll commented 3 years ago

Here is my JavaScript for handling giveaways:

const { GiveawaysManager } = require("discord-giveaways")

module.exports = async (Bot) => {
    class GiveawayManagerWithOwnDatabase extends GiveawaysManager {
        async getAllGiveaways(){
            return await Bot.Database.get("giveaways")
        }

        async saveGiveaway(MessageID, GiveawayData){
            await Bot.Database.push("giveaways", GiveawayData)

            return true
        }

        async editGiveaway(MessageID, NewGiveawayData){
            const Giveaways = await Bot.Database.get("giveaways")
            const NewGiveawaysArray = Giveaways.filter((giveaway) => giveaway.messageID !== MessageID)

            NewGiveawaysArray.push(NewGiveawayData)
            await Bot.Database.set("giveaways", NewGiveawaysArray)

            return true
        }

        async deleteGiveaway(MessageID){
            const Data = await Bot.Database.get("giveaways")
            const NewGiveawaysArray = Data.filter((giveaway) => giveaway.messageID !== MessageID)

            await Bot.Database.set("giveaways", NewGiveawaysArray)

            return true
        }
    }

    const Manager = new GiveawayManagerWithOwnDatabase(Bot, {
        storage: false,
        updateCountdownEvery: 10000,
        default: {
            botsCanWin: false,
            exemptPermissions: ["MANAGE_MESSAGES"],
            embedColor: Bot.Config.Embed.EmbedColor,
            embedColorEnd: "#FF0000",
            reaction: "🎉"
        }
    })

    Bot.GiveawayManager = Manager
}
KingCh1ll commented 3 years ago

Would you like my command script?

KingCh1ll commented 3 years ago

and was this only for 1 giveaway or have you started some more and did it happen there too?

For each one I created this error appeared more & more. It's not a mongoose problem since it saves into mongoDB (as I can see).

Nico105 commented 3 years ago

Oh, I forgot I actually fixed this error for someone a time ago, I just didn't recognize it. Remove storage: false from your manager options, it's what causes the error It will be removed from the examples in the next release.

KingCh1ll commented 3 years ago

Thank you so much for the help! I'm going to close this issue. Have a very nice day!