列出所有包含arg的单词


module.exports = {
name: "words",
/**
* @param {Client} client
* @param {Message} message
* @param {String[]} args
*/
run: async (client, message, args) => {
const searchWord = args
if(!searchWord) return;
const dictionary = require('../../json/dictionary');
const words = await dictionary.fetch()
message.channel.send(`.. ${words.filter((msg) => msg.content.has(searchWord))}`)
}
}

}
}

我试图得到包含一个参数的词,但代码也不起作用,我得到了一个错误TypeError: dictionary.fetch is not a function,我想这不是唯一的问题。有办法解决吗?

这只会在require('your_file')返回JSON值

如果你的字典的内容是一个数组,只需声明这样的词

const words = JSON.parse(dictionary);
// words = ["word", "word", "another word", "..."]

如果内容是Object ("{}"),则声明如下

const words = Object.keys(JSON.parse(dictionary));
// words = ["word", "word", "another word", "..."]

如果字在键中,则为Object。键,如果它是值,则放置Object。值。

JSON。parse方法将获取文件中的JSON。对象。key只接受Object的key。

最新更新