如果字符串包含文本,如何创建
如果字符串包含正在读取的文件,如何创建?
- 我的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.")
}
});
}
}
- 我的语言支持.txt
af
am
ar
az
be
bg
bn
bs
ca
ceb
co
cs
cy
da
de
el
en
eo
- 当我运行代码时,它总是显示等等我认为这不是一种语言。
- 怎么办如果字符串/文本包含在列表language-supported.txt中,我会做什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为有 1 个小缺失。
if(lang.includes(data)) {
应该是
if(data.includes(lang)) {
I think there is 1 small missing.
if(lang.includes(data)) {
should be
if(data.includes(lang)) {