2
votes

im trying to make a kicka command but it won't work because of this error i get "(node:13848) UnhandledPromiseRejectionWarning: TypeError: message.member.roles.some is not a function"

My code `client.on('message', async message => { if (!message.content.startsWith(prefix) || message.author.bot) return;

const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();

if(command === "kick") {
    if(!message.member.roles.some(r=>["Administrator", "Moderator"].includes(r.name)) )
      return message.reply("Sorry, you don't have permissions to use this!");
    let member = message.mentions.members.first() || message.guild.members.get(args[0]);
    if(!member)
      return message.reply("Please mention a valid member of this server");
    if(!member.kickable) 
      return message.reply("I cannot kick this user! Do they have a higher role? Do I have kick permissions?");
    let reason = args.slice(1).join(' ');
    if(!reason) reason = "No reason provided";

    await member.kick(reason)
      .catch(error => message.reply(`Sorry ${message.author} I couldn't kick because of : ${error}`));
    message.reply(`${member.user.tag} has been kicked by ${message.author.tag} because: ${reason}`);

  }});`
1
I forgot to tell that I get the error when trying to do the kick command! - CrackVibe
If message.member.roles.some is not a function, it means that message.member.roles is not an Array. Check what it is, by doing console.log, for example - blex

1 Answers

1
votes

If your discord.js version is 12.0.0 or over, it is message.member.roles.cache.some(). This also includes other changes such as message.guild.members.get(args[0]) is now message.guild.members.cache.get(args[0]). This is because of the newly added managers. You can read more about v12 changes at https://discordjs.guide/additional-info/changes-in-v12.html. If you are not on v12, message.member.roles in your code was most likely overwritten and no longer is a Collection.