【问题标题】:If a message is from 3 specific users , ignore them如果消息来自 3 个特定用户,请忽略他们
【发布时间】:2021-07-11 13:52:27
【问题描述】:

我想知道是否可以阻止特定用户使用机器人,例如如果用户 b 在 config.json 的黑名单中,则不能使用任何命令。谢谢

【问题讨论】:

    标签: node.js discord.js


    【解决方案1】:

    这是你可以使用的东西

    const bannedUsers = ['userid1', 'userid2', 'userid3'];
    client.on('message', msg => {
    if(bannedUsers.includes(msg.author.id)) return;
    //command execution code here
    })
    

    你必须把它放在你所有的client.on('message')听众中。

    【讨论】:

      【解决方案2】:

      你没有显示任何代码,但你可以尝试这样的处理命令的地方..

      //when bot receives a message
      if (message.author.id === 'blacklisted ids'){
         return;
      } else {
         //process commands
      }
      

      【讨论】:

      • 如果您不打算将太多用户列入黑名单,您可以手动添加每个列入黑名单的id;否则,您可以创建一个数组并使用 foreach 对照数组中每个列入黑名单的 id 检查 message.author.id
      • 不,你使用Array.prototype.includes 让它更快
      • 我的立场是正确的 - 很高兴知道未来;感谢您引起我的注意。
      猜你喜欢
      • 2011-07-27
      • 2012-09-18
      • 1970-01-01
      • 2019-12-11
      • 2021-09-02
      • 2022-01-24
      • 2014-07-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多