首页 > 解决方案 > 我如何才能使命令仅在您位于不和谐服务器中时才有效?

问题描述

假设有人想在另一台服务器上使用我的机器人。我想这样做,因此该命令仅在您在我的不和谐服务器中时才有效。如果他们在我的不和谐服务器中,他们可以在其他服务器中使用它。如果他们不是,我不希望他们能够使用它。

我已经尝试了很多事情,比如if (guild.member(USER_ID)没有运气。

let guild2 = client.guilds.get('598974868779958282'),
  user_id = message.author.id;

if (guild2.member(user_id)) {
  message.author.send("you are in the support server!")
}else{

  message.author.send("you are not in the support server!")
}

我希望它会返回直接消息“您不在支持服务器中!” 因为我不在那个公会中,但即使我不在公会中,它也总是返回“你在支持服务器中”。

标签: javascriptdiscorddiscord.js

解决方案


let guild2 = client.guilds.get('598974868779958282'),
  user_id = message.author.id;

if (guild2.members.has(user_id)) {
  message.author.send("you are in the support server!")
}else{

  message.author.send("you are not in the support server!")
}

该方法guild.member不存在,请guild.members改为尝试。


推荐阅读