如何将 "reason" 东西添加到禁止命令

How to add "reason" thing to ban command

我正在 node.js(不是 master)中编写一个 discord 机器人程序,我正在研究踢和禁止命令。我正在尝试让 BOT 写入用户的封禁日志。喜欢+ban @user 原因。我做了 +ban @user 但我无法做出合理的事情。

  if (!message.member.hasPermission("BAN_MEMBERS")) return;

  if (message.content.startsWith('+ban')) {
    const user = message.mentions.users.first();
    if (user) {
      const member = message.guild.member(user);
      if (member) {
        member.ban({
          reason: 'reason',
        }).then(() => {
          message.channel.send(`${user.tag} BAN!`);
        }).catch(err => {
          message.channel.send('Bu çar çok güçlü, banlayamıyorum! ');
          console.error(err);
        });
      } else {
        message.channel.send('Kullanıcı sunucuda değil.');
      }
    } else {
      message.channel.send('Adını ver banlayayım, sahip.');
    }
  }
});```

只需使用member.ban('reason here')。如果您需要删除以前的消息,请使用一个对象 并且 提供一个原因,例如:

member.ban({days: 2, reason: 'bad'});

现在,只需根据用户的原因使用此设置即可。使用变量作为参数数组的切片版本,用空格连接。

编辑: 显示上下文...

if (message.content.toLowerCase().startsWith('+ban')) { // changed to case insensitive command
  const member = message.mentions.members.first(); // keep in mind it isn't the best practice to use message.mentions to retrieve an argument
  if (!member) return message.channel.send('no member mentioned');
  let reason = args.slice(2).join(' '); // arguments should already be defined
  member.ban(reason)
  .then(message.channel.send('success'))
  .catch(err => {
    message.channel.send('something went wrong');
    console.error();
  });
}