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

RangeError: Maximum call stack size exceeded #250

Closed WideKan1 closed 3 years ago

WideKan1 commented 3 years ago

This error happens when I am trying to do role requirements.

Here is my role requirement code

else if(yesreq){
              await bot.giveawaysManager.start(message.channel, {
                time: ms(giveawayDuration),
                prize: giveawayPrize,
                winnerCount: giveawayWinners,
                     extraData: {
        Role: yesreq
        },

            });
}

My event:

manager.on('giveawayReactionAdded', (giveaway, member, reaction) => {
  let hey = giveaway.extraData.Role.slice(3, -1)
    if (!member.roles.cache.some(hey)) {
         reaction.users.remove(member.user);
             const hostembed = new Discord.MessageEmbed()
    .setTitle(`:x:`)
    .setColor('RED')
   member.send(hostembed).
    })
    }
});
Nico105 commented 3 years ago

If hey is a ID then you have to use .get(hey) but if it is a name then .some has to be a function .some(r => r.name === hey)

WideKan1 commented 3 years ago

@Nico105

I did

 let yuh = member.guild.roles.cache.get(hey)
    if (!member.roles.cache.some(yuh)) {
//code
}

It still same error

Nico105 commented 3 years ago

.some still has to be a function, means .some(r => r === yuh) now you just made an extra const to get the actual role but that was not really necessary

WideKan1 commented 3 years ago

@Nico105

I did

  if(!yuh) return
    if (!member.roles.cache.some(r => r === yuh)) {
    // code
    } 
It still doesn't work.

Here is the full error

      at propertyIsOnObject (/home/runner/WideDiscordBotReowWillow/node_modules/deepmerge/dist/cjs.js:64:28)
      at propertyIsUnsafe (/home/runner/WideDiscordBotReowWillow/node_modules/deepmerge/dist/cjs.js:74:9)
      at /home/runner/WideDiscordBotReowWillow/node_modules/deepmerge/dist/cjs.js:87:7
      at Array.forEach (<anonymous>)
      at mergeObject (/home/runner/WideDiscordBotReowWillow/node_modules/deepmerge/dist/cjs.js:86:18)
      at deepmerge (/home/runner/WideDiscordBotReowWillow/node_modules/deepmerge/dist/cjs.js:117:10)
      at cloneUnlessOtherwiseSpecified (/home/runner/WideDiscordBotReowWillow/node_modules/deepmerge/dist/cjs.js:34:5)
      at /home/runner/WideDiscordBotReowWillow/node_modules/deepmerge/dist/cjs.js:94:23
      at Array.forEach (<anonymous>)
      at mergeObject (/home/runner/WideDiscordBotReowWillow/node_modules/deepmerge/dist/cjs.js:86:18)
      at deepmerge (/home/runner/WideDiscordBotReowWillow/node_modules/deepmerge/dist/cjs.js:117:10)
      at cloneUnlessOtherwiseSpecified (/home/runner/WideDiscordBotReowWillow/node_modules/deepmerge/dist/cjs.js:34:5)
      at /home/runner/WideDiscordBotReowWillow/node_modules/deepmerge/dist/cjs.js:94:23
      at Array.forEach (<anonymous>)
      at mergeObject (/home/runner/WideDiscordBotReowWillow/node_modules/deepmerge/dist/cjs.js:86:18)
      at deepmerge (/home/runner/WideDiscordBotReowWillow/node_modules/deepmerge/dist/cjs.js:117:10)
      at cloneUnlessOtherwiseSpecified (/home/runner/WideDiscordBotReowWillow/node_modules/deepmerge/dist/cjs.js:34:5)
      at /home/runner/WideDiscordBotReowWillow/node_modules/deepmerge/dist/cjs.js:94:23
      at Array.forEach (<anonymous>)
      at mergeObject (/home/runner/WideDiscordBotReowWillow/node_modules/deepmerge/dist/cjs.js:86:18)
      at deepmerge (/home/runner/WideDiscordBotReowWillow/node_modules/deepmerge/dist/cjs.js:117:10)
      at cloneUnlessOtherwiseSpecified (/home/runner/WideDiscordBotReowWillow/node_modules/deepmerge/dist/cjs.js:34:5)
      at /home/runner/WideDiscordBotReowWillow/node_modules/deepmerge/dist/cjs.js:94:23
      at Array.forEach (<anonymous>)
      at mergeObject (/home/runner/WideDiscordBotReowWillow/node_modules/deepmerge/dist/cjs.js:86:18)
      at deepmerge (/home/runner/WideDiscordBotReowWillow/node_modules/deepmerge/dist/cjs.js:117:10)
      at cloneUnlessOtherwiseSpecified (/home/runner/WideDiscordBotReowWillow/node_modules/deepmerge/dist/cjs.js:34:5)
      at /home/runner/WideDiscordBotReowWillow/node_modules/deepmerge/dist/cjs.js:94:23
}
Nico105 commented 3 years ago

How is yesreq defined in your start command?

WideKan1 commented 3 years ago

How is yesreq defined in your start command?

let req = args[3]
let yesreq = message.guild.roles.cache.get(req)  
Nico105 commented 3 years ago

The problem is very likely because yesreq would be a class and deepmerge (which discord-giveaways uses) cannot merge classes So just save the ID of the role instead of the role itself in extraData = extraData: { Role: yesreq.id }

In your event you then can just do

if (!member.roles.cache.get(giveaway.extraData.Role)
WideKan1 commented 3 years ago

The problem is very likely because yesreq would be a class and deepmerge (which discord-giveaways uses) cannot merge classes So just save the ID of the role instead of the role itself in extraData = extraData: { Role: yesreq.id }

In your event you then can just do

if (!member.roles.cache.get(giveaway.extraData.Role)

Ahh ok that gets rid of the error but there's a new problem

 Unhandled Rejection at Promise Promise {
  <rejected> SyntaxError: Failed to parse value of giveaways, try passing a raw option to get the raw value
      at /home/runner/WideDiscordBotReowWillow/node_modules/@replit/database/index.js:36:17
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
      at async Client.get (/home/runner/WideDiscordBotReowWillow/node_modules/@replit/database/index.js:20:12)
      at async GiveawayManagerWithOwnDatabase.editGiveaway (/home/runner/WideDiscordBotReowWillow/index.js:93:27)
}

Extra Info (I don't know if it is necessary) I use replit and use this database https://github.com/Androz2091/discord-giveaways/commit/0b5ecb54d939882401ec1dfd8a8f8af14d6eceb4

Nico105 commented 3 years ago

Could it be it's because some giveaways were saved with the role class in the db? If so then could you try await db.delete("giveaways") clearing all giveaways once

WideKan1 commented 3 years ago

Could it be it's because some giveaways were saved with the role class in the db? If so then could you try await db.delete("giveaways") clearing all giveaways once

Where do I put the code

Nico105 commented 3 years ago

You can put it at the start of the (async () => block in the file where you have your custom db code

WideKan1 commented 3 years ago

You can put it at the start of the (async () => block in the file where you have your custom db code

Same Error

WideKan1 commented 3 years ago

Ok I am using quick.db for now and it gets rid of the error, but then a new error comes out.

TypeError: Cannot read property 'Role' of undefined

The code:

manager.on('giveawayReactionAdded', (giveaway, member, reaction) => {
  let hey = giveaway.extraData.Role

  let yuh = member.guild.roles.cache.get(hey)
    if (!member.roles.cache.some(r => r === yuh)) {
   //rest of code

    }
})

other code: extraData: {Role: yesreq.id}

Nico105 commented 3 years ago

Not every giveaway of yours has that property remember, so you just have to make a if statement around your event code = if (giveaway.extraData.Role)

WideKan1 commented 3 years ago

Not every giveaway of yours has that property remember, so you just have to make a if statement around your event code = if (giveaway.extraData.Role)

  let hey = giveaway.extraData.Role
if(!hey) return
if(hey){
//rest of code

    }

Same error

After that I also put

if(!giveaway.extraData) return console.log('mhm')

And it did log.

Dragonizedpizza commented 3 years ago

The problem is very likely because yesreq would be a class and deepmerge (which discord-giveaways uses) cannot merge classes So just save the ID of the role instead of the role itself in extraData = extraData: { Role: yesreq.id }

In your event you then can just do

if (!member.roles.cache.get(giveaway.extraData.Role)

I don't think its that. I put the entire class in the extraData part.

Dragonizedpizza commented 3 years ago

@WideIrenaKan2 I can't tell what you did wrong, but here's what I do:

module.exports = {
  name: "giveawayReactionAdded",
  run: async (giveaway, member, reaction) => {
    if (
      giveaway.extraData.role !== "null" &&
      !member.roles.cache.get(giveaway.extraData.role.id)
    ) {
      reaction.users.remove(member.user);
      member.send({
        embed: {
          title: "Requirement failed.",
          description: `You must have the role \`${giveaway.extraData.role.name}\` to participate in that giveaway.`,
        },
      });
    }
  },
};

or in your case,

manager.on('giveawayReactionAdded', async (giveaway, member, reaction) => {
    if (
      giveaway.extraData.role !== "null" &&
      !member.roles.cache.get(giveaway.extraData.role.id)
    ) {
      reaction.users.remove(member.user);
      member.send({
        embed: {
          title: "Requirement failed.",
          description: `You must have the role \`${giveaway.extraData.role.name}\` to participate in that giveaway.`,
        },
      });
    }
  };
WideKan1 commented 3 years ago

Still says role is undefined.

Extra info: I use a command handler for my commands (I don't know if that is helpful)

Dragonizedpizza commented 3 years ago

if role is undefined, then you tried to get the role wrong

WideKan1 commented 3 years ago

I didn't

Dragonizedpizza commented 3 years ago

could you try logging role, along with show how you get the role?

WideKan1 commented 3 years ago
let req = args[3]
let yesreq = message.guild.roles.cache.get(req) 
 bot.giveawaysManager.start(message.channel, {
                time: ms(giveawayDuration),
                prize: giveawayPrize,
                winnerCount: giveawayWinners,
                hostedBy: message.author,
                messages: {
                    giveaway: `**GIVEAWAY**`,
                    giveawayEnded: `**GIVEAWAY ENDED**`,
                    timeRemaining: "Time remaining: **{duration}**",
                    inviteToParticipate: `React with 🎉 to enter`,
                    winMessage: `Congratulations {winners}! `,
                    embedFooter: "Giveaway time!",
                    noWinner: "Couldn't determine a winner",
                    hostedBy: "Hosted by {user}",
                    winners: "winner(s)",
                    endedAt: "Ends at",
                    extraData: {role: yesreq.id},
                    units: {
                        seconds: "seconds",
                        minutes: "minutes",
                        hours: "hours",
                        days: "days",
                        pluralS: false
                    }
                }
            });
Dragonizedpizza commented 3 years ago

did you log the roal doe

WideKan1 commented 3 years ago

console.log(yesreq.id)

It shows the role ID

Nico105 commented 3 years ago

Not every giveaway of yours has that property remember, so you just have to make a if statement around your event code = if (giveaway.extraData.Role)

  let hey = giveaway.extraData.Role
if(!hey) return
if(hey){
//rest of code

    }

Same error

After that I also put

if(!giveaway.extraData) return console.log('mhm')

And it did log.

Oh yeah, I forgot that some giveaways of yours don't even have extraData because of if else in your start command, so just check both

if (giveaway.extraData && giveaway.extraData.Role) {
 // code
}
Nico105 commented 3 years ago

The problem is very likely because yesreq would be a class and deepmerge (which discord-giveaways uses) cannot merge classes So just save the ID of the role instead of the role itself in extraData = extraData: { Role: yesreq.id } In your event you then can just do

if (!member.roles.cache.get(giveaway.extraData.Role)

I don't think its that. I put the entire class in the extraData part.

Ah yeah you're right, deepmerge should only merge the messages if I don't forget smth, but then it's weird why the error fired before and stopped after the change. I will look into that somewhen.

WideKan1 commented 3 years ago

Ok I tried with local host and it still said role is undefined

(node:5444) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'role' of undefined
    at GiveawaysManager.<anonymous> (C:\Users\ASUS\Documents\widetest\index.js:115:31)
    at GiveawaysManager.emit (events.js:315:20)
    at GiveawaysManager._handleRawPacket (C:\Users\ASUS\node_modules\discord-giveaways\src\Manager.js:435:18)        
    at Client.<anonymous> (C:\Users\ASUS\node_modules\discord-giveaways\src\Manager.js:464:48)
    at Client.emit (events.js:315:20)
Nico105 commented 3 years ago

Ah, did you saw my second last post?

nicopenaloza commented 3 years ago

Ok I tried with local host and it still said role is undefined

(node:5444) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'role' of undefined
    at GiveawaysManager.<anonymous> (C:\Users\ASUS\Documents\widetest\index.js:115:31)
    at GiveawaysManager.emit (events.js:315:20)
    at GiveawaysManager._handleRawPacket (C:\Users\ASUS\node_modules\discord-giveaways\src\Manager.js:435:18)        
    at Client.<anonymous> (C:\Users\ASUS\node_modules\discord-giveaways\src\Manager.js:464:48)
    at Client.emit (events.js:315:20)

check if you are not receiving a null object by extraData, you could use a console.log() to see it.

WideKan1 commented 3 years ago

Ok I will try tomorrow

WideKan1 commented 3 years ago

Ok, I did

console.log(giveaway.extraData)
console.log(giveaway.extraData.role)

And it says

undefined Cannot read the property of role of undefined

Here is my full gstart command, you can see if I did anything wrong

https://sourceb.in/drSvjYcb2q

Nico105 commented 3 years ago

Ok, I did

console.log(giveaway.extraData)
console.log(giveaway.extraData.role)

And it says

undefined Cannot read the property of role of undefined

Here is my full gstart command, you can see if I did anything wrong

https://sourceb.in/drSvjYcb2q

You put extraData into the messages object, move it out of it

WideKan1 commented 3 years ago

Wow, how could I miss that? Thank you! It works in local host, I will try using replit database now.

WideKan1 commented 3 years ago

Thank you, it is working perfectly now! I am really sorry I wasted your time to help me, it's my fault, I should've looked carefully.