Home > database >  How do I create if a string includes a text
How do I create if a string includes a text

Time:03-02

How do I create if a string includes the file being read?

  • my index.js
if (command == "creategame") {
const lang = args[0]
const gameTypes = args[1]
const allLang = fs.readFileSync('language-supported.txt', 'utf-8')

if(!lang) {
    message.reply("Need language.\nExample: !creategame en character\n\n!creategame <language> <gameType> (ANIMALS/CHARACTER)")
} else {
    fs.readFile('./language-supported.txt', function (err, data) {
        if (err) throw err;

// here ima try if the stringMessage includes a text in language-supported.txt
        if(lang.includes(data)) {

            if(!gameTypes) {
                message.reply("Need game types.\nExample: !creategame en character\n\n!creategame <language> <gameType> (ANIMALS/CHARACTER)")
            } else {
                if(gameTypes == "animals" || gameTypes == "character") {
                if(fs.existsSync(gamePath)) {
                    const { language, gameTypes } = require(gamePath);
                    message.reply(`You already create a game, Type: ${gameTypes}, Language: ${language}`)
                } else {
                const conntent = `{ "languageGame": "${lang}", "gameTypes": "${gameTypes}" }`;
                message.reply("game created!")
                fs.writeFileSync(gamePath, conntent);
                }
                } else {
                    message.reply(`The bots only support gametype: **ANIMALS/CHARACTER** not a ${gameTypes}`)
                }
            }   
        } else {
            message.reply("wait i think thats not a Language.")
        }
      });
   
}
}
  • my language-supported.txt
af
am
ar
az
be
bg
bn
bs
ca
ceb
co
cs
cy
da
de
el
en
eo
  • when i run the codes, it always show wait i think thats not a Language.
  • how do i make if the string/text is included in the list language-supported.txt?

CodePudding user response:

I think there is 1 small missing.

if(lang.includes(data)) {

should be

if(data.includes(lang)) {

  • Related