切换功能?

时间:2018-05-31 05:20:21

标签: node.js discord.js

所以我试图让我的机器人打开和关闭是否以全部大写形式发送消息。我的问题是,当我尝试更改变量值时,它不会改变。谁能帮助我?堆叠溢出和编程都是新的(ish,知道足以让我这么做)

1 个答案:

答案 0 :(得分:0)

Here we can use the toUpperCase() method (or the toLowerCase() method) to make our string go all lower case or all upper case. for example:

let string = "example"
let toggledString = string.toUpperCase()

then later on we can have an if statement:

if (command == toggled) {
    message.channel.send(toggledString)
} else {
    message.channel.send(string)
}

the toggled string would output EXAMPLE while the other will output example

As for why your variables aren't being reassigned you're probably declaring them using const which does not allow the variable to be changed. You can just change const to let or var to fix this.