簡體   English   中英

Discord.js v13 ReferenceError:成員未定義| 在踢命令中

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

所以基本上幾個月前我將這個機器人更新到 Discord.js v13,現在我回到這個(我忙於其他事情),我似乎無法弄清楚這個 Kick 命令出了什么問題。

錯誤

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)

踢.js | 踢命令 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: []
    });
  }
};

交互創建.js | 另一個出現在錯誤中的文件

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')]
          });
        }
      }
    }
  }
};

提前非常感謝!

在您的 Kick.js 文件的第 49 行中,您正在使用member.user.tag但您沒有定義member 添加這個:

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

在第 72 行,您試圖禁止用戶而不是公會成員。

改變這個:

await user.kick({ reason });

對此:

await member.kick({ reason });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM