discord - 命令限制
问题描述
如果它不在某个频道中,我正在尝试使命令不起作用。当我运行我的代码时,我得到这个错误: SyntaxError: Unexpected token '!'
module.exports = {
name: "kill",
desciprtion: "idk",
if (!message.channel.id === '794303555975643136') return;
const { member } = message;
member.roles.add('794308638125981726')
}
解决方案
在 JavaScript 和大多数其他语言中,您可以!
在函数中将not
.
例如,让我们采取message.member.hasPermission()
. 如果我们!
在开头添加,给我们:
if (!message.member.hasPermission('ADMINISTRATOR') return
我们基本上是在告诉客户,if the message member does **not** have the administrator permission, return the command
.
现在,让我们拿你的if statement
话说if (!message.channel.id === 'id') return
,你基本上是在告诉客户if not message id equals to id return the command
,让我们面对这完全没有意义。
当我们想将变量与某个值进行比较时,我们想告诉客户端if the variable is **not** equal to value, return the command
。因此,为什么,您应该将 if 语句修改为:
if (message.channel.id !== '794303555975643136') return;
很抱歉回答的很长,感觉就像给某人上了一课:p
推荐阅读
- java - 旧 servlet 应用程序的 OIDC 过滤器
- css - 没有额外容器的多个网格项目周围的边框?
- angular - 根据功能显示隐藏元素
- python - 防止 pip 升级依赖项
- javascript - 如何将html表单从一台服务器(coldfusion)提交到另一台(节点)?
- angular - 如何在 Ionic 3 中获取 ion-checkbox 多选值
- wordpress - 将 CSS 样式应用于悬停时访问的链接
- excel - Excel VBA:到期后禁用代码
- java - 扩展 ArrayList
: 如何在其中使用 Date 对象? - pandas - 如何覆盖熊猫数据框子类中的访问器