i keep getting this error unexpected token => in these lines of code please help (this is for a discord bot btw)
client.on(‘message’, message => {
if(message.content.startsWith(“em!mute”)){
if(!message.member.hasPermission(“KICK_MEMBERS”)) return;
message.channel.send(“You don’t have permission to do that!”)
let member = message.mentions.members.first()
let reason = message.content.split (" ").slice(2).join( " ")
if(!reason) reason = “No reason specified.”
if(!role) return message.channel.send(“You don’t have the muted role in your server!”)
if(!member) return message.channel.send(“You didn’t mention a member!”)
member.roles.add(role)
.then() => {
}
}
You get the same error, a new one or it just doesn’t work? Comment out everything in it to the point that you don’t get an error about the unexpected token. Let some of the code back in as you can. That means the outer if(message.content line for instance and it’s matching ending brace.
I can barely read it because it is all squished together and does maybe 3 or 4 things. I spot if(!role) but I’m not sure I see where that has been assigned a value.
.
Your code was missing a closing brace in this sample, maybe it’s in your original code and you forgot to paste it.
There were a couple of other logical errors, like this:
if(!message.member.hasPermission(“KICK_MEMBERS”)) return;
message.channel.send(“You don’t have permission to do that!”)
This will always send the message “You don’t have permission to do that!” no matter what!
Here is how I’d improve your code:
client.on('message', message => {
if(message.content.startsWith("em!mute")){
if(!message.member.hasPermission("KICK_MEMBERS")) return message.channel.send("You don’t have permission to do that!");
let member = message.mentions.members.first();
let reason = message.content.split(" ").slice(2).join(" ");
if(!reason) reason = "No reason specified."
if(!role) return message.channel.send("You don’t have the muted role in your server!");
if(!member) return message.channel.send("You didn’t mention a member!");
member.roles.add(role);
}
}
Use triple backticks ``` to paste code with nice formatting in this forum