【问题标题】:How to add "reason" thing to ban command如何添加“原因”来禁止命令
【发布时间】:2019-09-03 09:58:49
【问题描述】:

我正在 node.js 中编写一个不和谐的机器人(不是主控程序),我正在编写一个踢和禁止命令。我正在尝试让 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.');
    }
  }
});```

【问题讨论】:

标签: node.js bots discord discord.js


【解决方案1】:

只需使用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();
  });
}

【讨论】:

  • 我不知道在哪里添加这些代码。可以吗?
  • 已编辑答案以显示上下文。如果您不知道如何将消息解析为参数,请阅读this
猜你喜欢
  • 2021-06-01
  • 2019-02-15
  • 1970-01-01
  • 2021-04-03
  • 1970-01-01
  • 1970-01-01
  • 2017-04-26
  • 2018-11-07
  • 2021-07-27
相关资源
最近更新 更多