Skip to content Skip to sidebar Skip to footer

Discord.js V12 'filter' Undefined

So I was updating my bot to discord.js V12 the command ;whois is bringing up an error (node:553) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'filter' of undef

Solution 1:

To access the GuildMember's roles collection in v12 you need to use cache.

const roles = member.roles.cache.filter(r => r.id !== message.guild.id).map(r => r).join(", ") || 'none';

Solution 2:

Discord.js Guide:

v12 introduces the concept of managers, you will no longer be able to directly use collection methods such as Collection#get on data structures like Client#users. You will now have to directly ask for cache on a manager before trying to use collection methods. Any method that is called directly on a manager will call the API, such as GuildMemberManager#fetch and MessageManager#delete

  • OLD: client.users.get('123456789012345678');
  • NEW: client.users.cache.get('123456789012345678');
  • OLD: channel.messages.get('123456789012345678');
  • NEW: channel.messages.cache.get('123456789012345678');
  • OLD: guild.members.get('123456789012345678');
  • NEW: guild.members.cache.get('123456789012345678');

Refer to Updating from v11 to v12 for more

Post a Comment for "Discord.js V12 'filter' Undefined"