parsing err! ‘return’ outside of function

So, I wanted to add a unban command.
This my code so far:

if (command === ":unban") {
    if (!msg.member.hasPermission("BAN_MEMBERS")) {
        return`**${}**, You do not have perms to unban someone`);
    if (!"BAN_MEMBERS")) {
        return`**${}**, I do not have perms to unban someone`);
    let userID = args[0]
    msg.guild.fetchBans().then(bans=> {
        if (bans.size == 0) return 
        let bUser = bans.find(b => == userID);
        if (!bUser) return

when I run it it gives me this error:

parsing error: 'return' outside of function

can somebody help me out on this because im new to this stuff


You cant use a return function, with nothing to return to. Returning out of those if-cases is not possible. You could put that code in a separate function and call that, then returning would not bring an error. A simple rewrite of your code using a bool should fix the issue tho:

client.on("messageCreate", message => {
  if(message.content === "!ping"){"pong")
  } else if(message.content === '!unban') {
    let permissionToKick = true;

    if(!message.member.hasPermission("BAN_MEMBERS")) {
      permissionToKick = false`**${}**, You do not have perms to unban someone`)

    if(!"BAN_MEMBERS")) {
      permissionToKick = false`**${}**, I do not have perms to unban someone`)

    if(permissionToKick) {
      let userID = args[0] //args[] are not defined, and this will throw an error
        message.guild.fetchBans().then(bans=> {
        if(!bans.size === 0) {
          let bUser = bans.find(b => === userID)
          if(bUser) {

PS: I see you are using args[] in your code, but args are nowhere to be defined. I won’t write all the code for you, since Stackoverflow is not Code-writing platform. I would advise you learn the basics of JavaScript and discord.js first.

A good source to learn JavaScript is W3Schools. If you understand the basics, I advise you to read the Documentation of Discord.js or follow the Discord.js guide