最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

搜索的对象阵列,以匹配输入

IT培训 admin 6浏览 0评论

搜索的对象阵列,以匹配输入

所以,我试图让一些工作,我打砖墙,我一定只是由于经验不足我。

在下面的代码,我想采取什么样的用户将在(!激活[卡名])的集换卡游戏(爆丸),并有系统从全部小写,没有空格的格式找到卡。我有一个具有设置为对象的卡单独cardlist.js文件。我试过很多不同的方式,我不断收到“____是不是一个函数”或只是不能由于某种原因cardlist文件中找到的项目。我知道,我一直在整个的尝试小时跳舞周围。

const Discord = require("discord.js");
const botconfig = require("../botconfig.json");
const cardlist = require('../cardlist.js');

module.exports.run = async (bot, message, args) => {
    //console.log("works");
    //let aUser = `${message.author}`;
    let aCard = message.content.slice(10);
    oCard = Object.filter(function(cardlist){ 
        return cardlist.name === aCard });
    if (aCard === oCard) {
        console.log('Cards match!');
     } else {
         console.log(`Cannot find ${aCard}`)
     }
    }

module.exports.help = {
    name: "activate"
}
回答如下:

Object.filter不存在,即使它:什么是Object?

既然你有一个命令处理程序,你在这里一段代码可以接收来自它只有“论据”,即不是整个消息,但仅会发生什么砰命令(这里!activate)后,这将避免勉强可以理解.slice(10)。无论如何。

你不想匹配的人类可读的名称显然("Pyrus Hyper Dragonoid"),你要匹配的密钥名称(pyrushyperdragonoid,最好不要阅读障碍)。你可以解决它像任何对象,用括号内为关键:

// aCard sounds like an object of the same nature as oCard, but it's just a string
var userInput = message.content.slice(10);
var oCard = cardlist[userInput];
// then you can test
if (oCard) {
  console.log(`You legitimately chose to activate ${oCard.name}!`);
  // here oCard is a sub-object of cardlist, such as { image: '...', name: '...', faction... }
} else {
  console.log(`No mighty beast answered to the name ${userInput}!`);
  // here oCard is undefined
}

搜索的对象阵列,以匹配输入

所以,我试图让一些工作,我打砖墙,我一定只是由于经验不足我。

在下面的代码,我想采取什么样的用户将在(!激活[卡名])的集换卡游戏(爆丸),并有系统从全部小写,没有空格的格式找到卡。我有一个具有设置为对象的卡单独cardlist.js文件。我试过很多不同的方式,我不断收到“____是不是一个函数”或只是不能由于某种原因cardlist文件中找到的项目。我知道,我一直在整个的尝试小时跳舞周围。

const Discord = require("discord.js");
const botconfig = require("../botconfig.json");
const cardlist = require('../cardlist.js');

module.exports.run = async (bot, message, args) => {
    //console.log("works");
    //let aUser = `${message.author}`;
    let aCard = message.content.slice(10);
    oCard = Object.filter(function(cardlist){ 
        return cardlist.name === aCard });
    if (aCard === oCard) {
        console.log('Cards match!');
     } else {
         console.log(`Cannot find ${aCard}`)
     }
    }

module.exports.help = {
    name: "activate"
}
回答如下:

Object.filter不存在,即使它:什么是Object?

既然你有一个命令处理程序,你在这里一段代码可以接收来自它只有“论据”,即不是整个消息,但仅会发生什么砰命令(这里!activate)后,这将避免勉强可以理解.slice(10)。无论如何。

你不想匹配的人类可读的名称显然("Pyrus Hyper Dragonoid"),你要匹配的密钥名称(pyrushyperdragonoid,最好不要阅读障碍)。你可以解决它像任何对象,用括号内为关键:

// aCard sounds like an object of the same nature as oCard, but it's just a string
var userInput = message.content.slice(10);
var oCard = cardlist[userInput];
// then you can test
if (oCard) {
  console.log(`You legitimately chose to activate ${oCard.name}!`);
  // here oCard is a sub-object of cardlist, such as { image: '...', name: '...', faction... }
} else {
  console.log(`No mighty beast answered to the name ${userInput}!`);
  // here oCard is undefined
}

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论