简体   繁体   English

Discord.js v13 ReferenceError:成员未定义| 在踢命令中

[英]Discord.js v13 ReferenceError: member is not defined | in a kick command

So basically I was updating this bot to Discord.js v13 a few months ago and now that I got back to this (I got busy with other things), I can't seem to figure out what went wrong with this Kick command.所以基本上几个月前我将这个机器人更新到 Discord.js v13,现在我回到这个(我忙于其他事情),我似乎无法弄清楚这个 Kick 命令出了什么问题。

The Error错误

ReferenceError: member is not defined
    at Object.run (C:\Users\Admin\OneDrive\Desktop\mybots\testbot\src\Commands\Moderation\Kick.js:49:30)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async run (C:\Users\Admin\OneDrive\Desktop\mybots\testbot\src\Events\InteractionCreate.js:32:11)

kick.js |踢.js | The kick command src踢命令 src

const { confirm } = require('../../Structures/Utils');
const { MessageEmbed } = require('discord.js');

module.exports = {
  name: 'kick',
  description: 'Kick a member.',
  category: 'Moderation',
  options: [
    {
      name: 'user',
      description: 'Mention a user',
      required: true,
      type: 'USER'
    },
    {
      name: 'reason',
      description: 'Specify reason for kick',
      required: true,
      type: 'STRING'
    }
  ],
  permissions: 'KICK_MEMBERS',
  async run({ interaction, bot }) {
    const user = interaction.options.getMember('user');
    const reason = interaction.options.getString('reason');

    if (!user.kickable)
      return interaction.reply({
        embeds: [new MessageEmbed().setColor('RED').setDescription(`I don't have permissions to kick ${user}.`)]
      });

    if (user.id === interaction.user.id)
      return interaction.reply({
        embeds: [new MessageEmbed().setColor('RED').setDescription(`You cannot kick yourself.`)]
      });

    const confirmation = await confirm(
      interaction,
      new MessageEmbed()
        .setTitle('Pending Conformation')
        .setColor('ORANGE')
        .setDescription(`Are you sure you want to kick ${user} for reason: \`${reason}\`?`)
        .setFooter({ text: 'You have 60 seconds.' })
    );

    if (confirmation.proceed) {
      const embed = new MessageEmbed()
        .setColor('ORANGE')
        .setDescription(`**${member.user.tag}** was kicked for \`${reason}\`.`);

      try {
        await user.send({
          embeds: [
            new MessageEmbed()
              .setTitle('You were kicked')
              .setColor('ORANGE')
              .addField('Reason', reason, false)
              .addField('Guild', interaction.guild.name, false)
              .addField('Date', time(new Date(), 'F'), false)
          ]
        });
      } catch (err) {
        embed.setFooter({
          text: `I was not able to DM inform them`
        });
      }
      await confirmation.i.update({
        embeds: [embed],
        components: []
      });

      await user.kick({ reason });
    }

    const embed = new MessageEmbed()
      .setTitle('Process Cancelled')
      .setColor('ORANGE')
      .setDescription(`${user} was not kicked.`);

    if (confirmation.reason) embed.setFooter({ text: confirmation.reason });

    await confirmation.i.update({
      embeds: [embed],
      components: []
    });
  }
};

InteractionCreate.js |交互创建.js | Another file that showed up in the error另一个出现在错误中的文件

const { MessageEmbed } = require('discord.js');
module.exports = {
  event: 'interactionCreate',
  async run(bot, interaction) {
    if (!interaction.isCommand()) return;

    const command = bot.commands.get(interaction.commandName);
    if (!command) return;

    if (command.permission && !interaction.member.permissions.has(command.permission)) {
      return await interaction.reply({
        embeds: [
          new MessageEmbed()
            .setColor('RED')
            .setDescription(`You require the \`${command.permission}\` to run this command.`)
        ]
      });
    } else {
      // If command's category is `NSFW` and if interaction.channel.nsfw is false, inform them to use the command in nsfw enabled channel.
      if (command.category === 'NSFW' && !interaction.channel.nsfw) {
        await interaction[interaction.deferred ? 'editReply' : interaction.replied ? 'followUp' : 'reply']({
          embeds: [
            new MessageEmbed()
              .setColor('RED')
              .setDescription('You can use this command in Age-Restricted/NSFW enabled channels only.')
              .setImage('https://i.imgur.com/oe4iK5i.gif')
          ],
          ephemeral: true
        });
      } else {
        try {
          await command.run({ interaction, bot, options: interaction.options, guild: interaction.guild });
        } catch (err) {
          console.log(err);

          await interaction[interaction.deferred ? 'editReply' : interaction.replied ? 'followUp' : 'reply']({
            embeds: [new MessageEmbed().setColor('RED').setDescription(err.message || 'Unexpected error')]
          });
        }
      }
    }
  }
};

Thanks a lot in advance!提前非常感谢!

In line 49 of your Kick.js file you're using member.user.tag but you did not define member .在您的 Kick.js 文件的第 49 行中,您正在使用member.user.tag但您没有定义member Add this:添加这个:

const user = interaction.options.getMember('user');
const member = interaction.guild.members.cache.get(user.id);

And in line 72, you're trying to ban the user instead of the guild member.在第 72 行,您试图禁止用户而不是公会成员。

Change this:改变这个:

await user.kick({ reason });

To this:对此:

await member.kick({ reason });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM