首页 > 解决方案 > Unhandled promise rejection: ReferenceError: member is not defined

问题描述

My code has an error: Unhandled promise rejection: ReferenceError: member is not defined. My code used to work, but now it just doesn't work. I haven't made any changes with the code. Here's my code:

module.exports = {
  name: "mute",
  description: "Mute a member from your server",

  async run(client, message, args) {
    if (!message.member.hasPermission("MANAGE_ROLES")) return message.channel.send('You can\'t use this command ( ͡° ͜ʖ ͡°).');

    let user = message.mentions.members.first() || message.guild.members.cache.get(args[0]);

    if (!user) message.channel.send("Please tag a user to mute.");
    if (user.id === message.author.id) return message.channel.send('lmao you can\'t mute yourself');
    if (!member.bannable) return message.channel.send('This user can\'t be muted.');

    let role = message.guild.roles.cache.find(x => x.name === "Muted");

    if (!role) return message.channel.send("Something went wrong.");

    let reason = args.slice(1).join(" ");
    if (reason === null) reason = "Unspecified"

    user.roles.add(role);

    await message.channel.send(`${user} was muted. That was nice.`);
  }
}

标签: discord.js

解决方案


将此行更改if (!member.bannable) return message.channel.send('This user can\'t be muted.');if (!user.bannable) return message.channel.send('This user can\'t be muted.');


推荐阅读