I'm trying to make a system in discord.js version 12 where if you have my vanity invite in your status, you get a supporter role
Whenever I try this it always says TypeError: Cannot read property 'find' of undefined
Here is my code
const roleID = "MyRoleID"
const inviteLink = "discord.gg/MyVanityInvite"
client.on('presenceUpdate', (_oldPresence, newPresence) => {
const member = newPresence.member
if (member) {
// Ignore members who already have the role
if (!member.roles.cache.has(roleID)) {
console.log(newPresence)
const customStatus = newPresence.activities.find(activity => activity.type === 'CUSTOM_STATUS').state
if (customStatus) {
if (customStatus.includes(inviteLink)) {
member.roles.add(roleID)
.catch(console.error)
}
}
}
}
})
<Presence>.activities returns an array of activities, you don't need to get the cache, just find directly like:
newPresence.activities.find(activity => activity.type === 'CUSTOM_STATUS').state