Somehow unexpected identifier

(node.js) At compilation, I encounter this:

await member.kick(reason)

SyntaxError: Unexpected identifier
    at createScript (vm.js:74:10)
    at Object.runInThisContext (vm.js:116:10)
    at Module._compile (module.js:533:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3

Here’s the code:

const JCMD = { //the commands.
  kick: {
    desc: "[mention/user ID] Kicks the mentioned user or the user with the mentioned ID.",
    perm: "KICK_MEMBERS",
    argCount: 1,
    func: function(message, args) {
      let member = message.mentions.members.first() || message.guild.members.get(args[0]);
      if (!member)
      	return message.reply("Please mention a valid member of this server");
      if (!member.kickable)
      	return message.reply("I cannot kick this user! Do they have a higher role? Do I have kick permissions?");

      let reason = args.slice(1).join(' ');
      if (!reason) reason = "No reason provided";

      await member.kick(reason)
      	.catch(error => message.reply(`Sorry ${} I couldn't kick because of : ${error}`));
      message.reply(`${member.user.tag} has been kicked by ${} because: ${reason}`);

Any help from the community would be appreciated.

UPDATE: I fixed the issue, the problem was that await was used inside a function that wasn’t async.

1 Like