Closed WideKan1 closed 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)
@Nico105
I did
let yuh = member.guild.roles.cache.get(hey)
if (!member.roles.cache.some(yuh)) {
//code
}
It still same error
.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
@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
}
How is yesreq
defined in your start command?
How is
yesreq
defined in your start command?
let req = args[3]
let yesreq = message.guild.roles.cache.get(req)
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)
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 inextraData
=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
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
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
You can put it at the start of the (async () =>
block in the file where you have your custom db code
You can put it at the start of the
(async () =>
block in the file where you have your custom db code
Same Error
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}
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)
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.
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 inextraData
=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.
@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.`,
},
});
}
};
Still says role is undefined.
Extra info: I use a command handler for my commands (I don't know if that is helpful)
if role is undefined, then you tried to get the role wrong
I didn't
could you try logging role, along with show how you get the role?
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
}
}
});
did you log the roal doe
console.log(yesreq.id)
It shows the role ID
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
}
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 inextraData
=extraData: { Role: yesreq.id }
In your event you then can just doif (!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.
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)
Ah, did you saw my second last post?
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.
Ok I will try tomorrow
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
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
You put extraData
into the messages
object, move it out of it
Wow, how could I miss that? Thank you! It works in local host, I will try using replit database now.
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.
This error happens when I am trying to do role requirements.
Here is my role requirement code
My event: