Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
720 views
in Technique[技术] by (71.8m points)

discord.js - 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.`);
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Change this line if (!member.bannable) return message.channel.send('This user can't be muted.'); into if (!user.bannable) return message.channel.send('This user can't be muted.');


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...