Unban命令Discord.js V12

时间:2020-10-06 06:38:59

标签: javascript node.js discord discord.js

我使用discord.js v12发出了unban命令。每当我运行命令时,都会出现错误。我对编码有点陌生,我自己无法解决错误。这是unban命令的代码:

$( "#mytest" ).removeClass( "is-collapsed" );
$( "#mytest" ).addClass( "is-expanded" );

正如我之前提到的,运行命令时出现错误。这是我得到的错误:

const { MessageEmbed } = require('discord.js');

const rgx = /^(?:<@!?)?(\d+)>?$/;

module.exports = {
    name: "unban",
    description: "Unbans a member from the server",

  async run(message, args) {
    const id = args[0];
    if (!rgx.test(id)) return message.channel.send('Please provide a valid user ID');
    const bannedUsers = await message.guild.fetchBans();
    const user = bannedUsers.get(id).user;
    if (!user) return message.channel.send('Unable to find user, please check the provided ID');

    let reason = args.slice(1).join(' ');
    if (!reason) reason = '`None`';
    if (reason.length > 1024) reason = reason.slice(0, 1021) + '...';

    await message.guild.members.unban(user, reason);
    const embed = new MessageEmbed()
      .setTitle('Unban Member')
      .setDescription(`${user.tag} was successfully unbanned.`)
      .addField('Moderator', message.member, true)
      .addField('Member', user.tag, true)
      .addField('Reason', reason)
      .setFooter(message.member.displayName,  message.author.displayAvatarURL({ dynamic: true }))
      .setTimestamp()
      .setColor(message.guild.me.displayHexColor);

    message.channel.send(embed);
  }
};

我不明白如何解决该问题。你能帮我吗?预先感谢!

1 个答案:

答案 0 :(得分:0)

运行命令时,必须确保 index.js 使用正确的参数执行命令:

index.js

command.run(message, args)

不是这样:

command.run(args, message) // Or something like that