如果字符串包含文本,如何创建

发布于 2025-01-11 05:36:18 字数 1937 浏览 0 评论 0原文

如果字符串包含正在读取的文件,如何创建?

  • 我的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绅刃 2025-01-18 05:36:18

我认为有 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)) {

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文