0
votes

Im trying to make a kickfunctionality where if AdminRole types /kick @user it kicks them but if someone in MemberRole tries saying /kick @user it says back Sorry, you don't have permissions to use this!

client.on("message", (message) => 
{
if (message.content.startsWith("/kick")) 
    //checking if user is an admin role
    if (message.member.roles.find('AdminRole'))
        {
            var member= message.mentions.members.first();
             // Kick
    member.kick().then((member) => {
        // Successmessage
        message.channel.send(":wave: " + member.displayName + " has been successfully kicked :point_right: ");
    }).catch(() => {
         // Failmessage
        message.channel.send("Sorry, command failed");
    });
}

  if (message.member.roles.find('MemberRole'))
    {
        message.reply("Sorry, you don't have permissions to use this!");
    }

});

Here is the error it spits back out, keep in mind it only spits this error when someone types the /kickcommand regardless of role

if (typeof value === 'undefined') throw new Error('Value must be specified.'); ^

Error: Value must be specified. at Map.find (/Users/MainUser/Desktop/bot/node_modules/discord.js/src/util/Collection.js:499:45) at Client.client.on (/Users/MainUser/Desktop/bot/index.js:12:34) at Client.emit (events.js:198:13) at MessageCreateHandler.handle (/Users/MainUser/Desktop/bot/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34) at WebSocketPacketManager.handle (/Users/MainUser/Desktop/bot/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:105:65) at WebSocketConnection.onPacket (/Users/MainUser/Desktop/bot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:333:35) at WebSocketConnection.onMessage (/Users/MainUser/Desktop/bot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:296:17) at WebSocket.onMessage (/Users/MainUser/Desktop/bot/node_modules/ws/lib/event-target.js:120:16) at WebSocket.emit (events.js:198:13) at Receiver.receiverOnMessage (/Users/MainUser/Desktop/bot/node_modules/ws/lib/websocket.js:789:20)

1

1 Answers

2
votes

Your error is coming from your current usage of Collection.find().

Incorrect: Collection.find('property')
Deprecated: Collection.find('property', 'value')
Correct: Collection.find(element => element.property === value)

const prefix = '/';

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

  const [cmd, ...args] = message.content.trim().slice(prefix.length).split(/\s+/g);

  switch(cmd.toLowerCase()) {
    case 'kick':
      try {
        if (!message.guild) return await message.channel.send(':x: Guilds only.');
        if (!message.member.roles.find(r => r.name === 'Admin')) return await message.channel.send(':x: No permission.');
        if (!args[1] || !message.mentions.members.first()) return await message.channel.send(':x: No member provided.');

        const toKick = message.mentions.members.first();
        const reason = args.slice(2).join(' ') || 'No Reason';

        if (!toKick.kickable || toKick.roles.find(r => r.name === 'Admin')) return await message.channel.send(':x: No permission.');

        await toKick.kick(reason);
        await message.channel.send(`:wave: ${toKick.user.displayName} has been kicked.`);
      } catch(err) {
        console.error(err);
      }

      break;
  }
});