javascript - 我如何才能使命令仅在您位于不和谐服务器中时才有效?
问题描述
假设有人想在另一台服务器上使用我的机器人。我想这样做,因此该命令仅在您在我的不和谐服务器中时才有效。如果他们在我的不和谐服务器中,他们可以在其他服务器中使用它。如果他们不是,我不希望他们能够使用它。
我已经尝试了很多事情,比如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!")
}
我希望它会返回直接消息“您不在支持服务器中!” 因为我不在那个公会中,但即使我不在公会中,它也总是返回“你在支持服务器中”。
解决方案
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
改为尝试。
推荐阅读
- javascript - 路由中的动态组件在刷新后未在 Vue 中呈现
- c# - c# nuget 包没有出现在 VS 的引用中
- r - 你如何在 R 中改变你的情节的起点?
- typescript - 在 onUpdate Trigger Typescript 中未定义使用 Jest 和 context.params.userId 测试我的 cloudfunction
- postgresql - 为什么在 PostgreSQL 枚举类型数组中允许空值?
- docker - 从 CI 命令行运行 docker push --insecure-registries 或者至少没有 root 访问权限?
- github - GitHub 动作发布标签
- excel - Excel 计算和输出日期和时间
- ssl - TLS 实现:(使用 LibreSSL 库)当服务器证书具有通配符 SAN 类型时客户端握手失败:*test.example.com
- sql - 特定日期的汇率