在这种情况下,我将如何使用RETURN? (discord.js机器人)

问题描述 投票:0回答:1

我正在尝试制作一些人们必须付费才能使用的命令集。我把那部分记下来了,但是我很确定我在使用return函数时遇到了麻烦。

下面的代码使它能够发送错误消息,然后在发送命令输出之后立即发送!如果他们的用户ID不在数组中,我希望它仅发送错误消息。如果它们的ID在数组中,则发送常规命令用法(通过使用return,对吗?)

This is what a user who's not on the gold members array sees.

^^这是不在黄金成员数组中的用户看到的内容。我想要它,所以我添加的人的ID仅显示命令输出。不在该用户ID数组中的人将看到错误消息(Whoops)。

var Spark = require("sparkbots")
const Permission = Spark.permission("Golds")
Permission.setLevel(5)
module.exports = Permission;

Permission.code = (client, message) => {
    let golds = ['190916650143318016']
    if(!golds.includes(message.author.id)){
      return message.reply("Whoops! That's a ⭐ GOLD ⭐ user only command. Purchase gold here: https://willm.xyz/dis/gold")

    } else {
      return false }
}```
javascript node.js discord discord.js
1个回答
0
投票

您需要的是一个For ... of ...循环。 Here是一些信息

// here is an example
arr = ['1', '2', '3']
for (let i of arr) {
   console.log(i); // logs 1, 2, 3
}

因此,您需要做的是将if语句放入for循环中

let golds = ['ID', 'ID2', 'ID3']
for (let i of golds) {
  if( i === message.author.id)){
    // if in gold
  }
  else {
    // if not in gold
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.