'list all words containing an 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))}`)
}
}
}
}
I'm trying to get words that contains an arg but the code won't work also, I got an error TypeError: dictionary.fetch is not a function and I guess that's not the only problem. Any way to fix it?
Solution 1:[1]
THIS WILL ONLY WORK IF require('your_file') RETURNS A JSON VALUE
If the content of your dictionary is an array, juste declare words like this
const words = JSON.parse(dictionary);
// words = ["word", "word", "another word", "..."]
Else if the content is an Object ("{}"), declare words like that
const words = Object.keys(JSON.parse(dictionary));
// words = ["word", "word", "another word", "..."]
if the word is in the key, it is Object.keys, if it is the value then put Object.values instead.
The JSON.parse method will get the JSON in the file. The Object.keys will only take the Keys of an Object.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | DharmanBot |
