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.
Anything after a
returnstatement 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.