-1

I'd like to ask why lines 46 - 49 are unreachable in my discord.js script. I really don't know why it happened.



const TOKEN = "hidden"

const client = new Discord.Client({
    intents: [
        "GUILDS",
        "GUILD_MESSAGES"
    ]
})

client.on("ready", () => {
    console.log(`Logged in as ${client.user.tag}`)
})

client.on("messageCreate", (message) => {
    const prefix = "!";
    let msg = message.content;
    let channel = message.channelId;
    const cmd = messageArray[0];
    const messageArray = message.content.split(" ");
    const args = messageArray.slice(1);



    console.log(message)
    console.warn(msg)
    console.log(channel)
    if(msg == "!sayhi"){
        message.channel.send("Hi!")
        console.log(`Hi command initiated by someone!`)
    }
    if (cmd == '${prefix}kick'){
        if (!args[0]){
            return message.reply("Prosze kogos dac do tej komendy!")
**        const member = message.mentions.members.first() || message.guild.members.cache.find(x => x.user.username.toLowerCase() === args.slice(0).join(" ") || x.user.username === args[0]);
        if (!message.member.permissions.has("KICK_MEMBERS")){
            return message.reply("Potrzebujesz moderatora!")
        if (message.member.id === member.id){
            return message.reply("Nie wywalaj siebie, lol!")
        }
        if (!message.guild.me.permissions.has('KICK_MEMBERS')){
            return message.reply("Nie mam do tego permisji, wezwij admina!")
        }
        member.kick();
        message.channel.send(`${member} zostal wywalony z serwera!`)

        }
        }**
    }

}
)

client.login(TOKEN)

I tried to make it more indented, change brackets, add semicolons but nothing worked. It just stayed "unreachable" for VSCode and node.js, I believe discord too.

isherwood
  • 58,414
  • 16
  • 114
  • 157
Malexz
  • 1
  • I guess the lines you're talking about are the ones with the stars at the beginning? They're unreachable because you return in the line above. Add a closing bracket `}` before the line (and after the return statement). – timlg07 Dec 29 '22 at 21:13

1 Answers1

-1

Anything after a return statement is unreachable code. If you are baffled by the fact, it may be because you did not close the brackets of the IF. Your mind is thinking this is inside an IF by itself but the code is telling you otherwise.

if (!args[0]) {
    return message.reply(...);
} // <----------  HERE.  You don't have this.  Perhaps this is what you think you have?
José Ramírez
  • 872
  • 5
  • 7