【问题标题】:Why does it say the wrong Message?为什么它说错误的消息?
【发布时间】:2020-08-04 16:11:11
【问题描述】:
else if (message.content.startsWith(prefix + 'test2')) //you can change command name here - not recommended but you can :)
{
    message.reply('**Just a Test2**');
        fs.truncate('../ConsoleClient/Console/output.txt', 0, function(){});
            setTimeout(function () {
                var out = fs.readFileSync('../ConsoleClient/RaidAlerts/messages.txt', 'utf-8').toString();
                var out3 = "test2";
                if(out == "stone")
                {
                    out3 = "Walls are fine";
                }
                else if(out == "air")
                {
                    out3 = "**WEEWOO** We´re being raided **WEEWOO**";
                }
                else if(out == "other")
                {
                    out3 = "Someone changed the block. Check ASAP";
                }
                const outembed = new Discord.RichEmbed()
                .setColor(0xe580ff)
                .setTimestamp()
                .setTitle('Walls')
                .addField('Status', "```" + out3 + out + "```")
                .setURL("https://de.namemc.com/profile/Memag")
                message.channel.sendEmbed(outembed)
                fs.truncate('../ConsoleClient/Console/output.txt', 0, function(){});
            }, 1000);
}

为什么它说“墙是细石其他”或“墙是细石空气”或“墙是细石”而不是“墙是好的”,“WEEWOO我们正在被突袭WEWOO ”和“有人更改了区块。尽快检查”?

【问题讨论】:

  • out 的值显然是 "other""stoneair""stonestone"'Status', "```" + out3 + out + "```" 连接 out3out
  • 不要在该表达式中包含out?我不知道您要达到什么目的,也不知道为什么要这样编写代码,但这很可能是问题所在。
  • @Pointy 问题是如果out 是其中之一,那么消息应该以“test2”或“有人更改了块。尽快检查”开头,但它以“墙很好”,尽管out 显然不是stone
  • @JosephSible-ReinstateMonica 应该从“test2”开始 — 究竟如何? out3 变量初始化为“test2”,但后来被覆盖。
  • @Pointy 因为“stonestone”和“stoneair”不等于“stone”、“air”或“other”。如果它是“其他”,那么它仍然应该以“有人更改了块。尽快检查”而不是“墙很好”开头。

标签: javascript discord.js minecraft


【解决方案1】:

试试

.addField('Status', "```" + out3 + "```")

并发布“/ConsoleClient/RaidAlerts/messages.txt”的内容

【讨论】:

  • messages.txt 实际上是“空的”,它只是在“石头”“空气”和“其他”之间变化
猜你喜欢
  • 1970-01-01
  • 2020-01-17
  • 2021-03-04
  • 1970-01-01
  • 2022-12-03
  • 1970-01-01
  • 2015-08-06
  • 1970-01-01
  • 2015-01-25
相关资源
最近更新 更多