【问题标题】:Discord.js (Mass Ban Command Fix)Discord.js(大规模禁令命令修复)
【发布时间】:2021-08-07 05:47:58
【问题描述】:

编码语言 = DISCORD.JS | COMMAND = R!MASSBAN

    client.on('message', async(message) => {  
   if (message.content === 'r!massban') {
message.guild.members.cache.forEach (member => {
    if (member.hasPermission("ADMINISTRATOR")) return;
  member.ban();
});
   }
 })```

It only bans me. I get no errors in console. It will only ban me and no one else even though it is above all other roles. This is my first coding project using discord.js and js. Any help will be appreciated.

【问题讨论】:

  • 您能否提供有关该问题的实际详细信息?你得到什么错误?什么没有按预期工作?

标签: javascript node.js discord discord.js command


【解决方案1】:

在我看来大部分都很好。

如果你是唯一被禁止的人,也许可以 console.log 缓存看看谁在里面。缓存只有最近活跃的人,所以如果是你的测试服务器,如果你是唯一活跃的人,你可能是缓存中唯一的人。

//编辑:

找出它可能是什么。用 .fetch() 替换缓存,fetch 也会获取离线成员。

client.on("message", (msg) => {
  if(msg.content.trim().startsWith("r!")){
    const [prefix, command] = msg.content.split("!");
    switch(command){
      case "massban":
        msg.guild.members.cache.forEach(member => {
          if(member.hasPermission("ADMINISTRATOR")) return;
          member.ban();
        });
        break;
      default:
        msg.reply("That command doesn't exist");
    }
  }
})

【讨论】:

    猜你喜欢
    • 2021-04-18
    • 2021-07-27
    • 2021-01-18
    • 2020-11-18
    • 2021-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-16
    相关资源
    最近更新 更多