如果字符串包含文本,我该如何创建
How do I create if a string includes a text
如果字符串包含正在读取的文件,我该如何创建?
- 我的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.")
}
});
}
}
- 我的语言-supported.txt
af
am
ar
az
be
bg
bn
bs
ca
ceb
co
cs
cy
da
de
el
en
eo
- 当我 运行 代码时,它总是显示 等等,我认为那不是语言。
- 如果 string/text 包含在列表 language-supported.txt 中,我该如何制作?
我觉得少了1个。
if(lang.includes(data)) {
应该是
if(data.includes(lang)) {
如果字符串包含正在读取的文件,我该如何创建?
- 我的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.")
}
});
}
}
- 我的语言-supported.txt
af
am
ar
az
be
bg
bn
bs
ca
ceb
co
cs
cy
da
de
el
en
eo
- 当我 运行 代码时,它总是显示 等等,我认为那不是语言。
- 如果 string/text 包含在列表 language-supported.txt 中,我该如何制作?
我觉得少了1个。
if(lang.includes(data)) {
应该是
if(data.includes(lang)) {