简体   繁体   English

如何使用 javascript discord bot 中的命令更改变量

[英]How to change a variable with a command in javascript discord bot

So, guys, I am trying to change variables in discord.js所以,伙计们,我正在尝试更改 discord.js 中的变量

what I am making is like that我正在做的就是这样

var Version = "10"

bot.on(bot.on("message", message => {
case 'Test'
    messages.channel.send(Version)
break;
})

What I am trying to make is Change the Version with a command example of a command我想要做的是使用命令的命令示例更改版本

+edit Version 100 +编辑版本 100

And the version variable will be changed and when you type test it will say 100 not gonna say 10并且版本变量将被更改,当您键入 test 时,它会说 100 不会说 10

I can tell you are very new to coding in javascript.我可以告诉您,您对 javascript 编码非常陌生。 I have written out some starter code for you to help you out.我已经为你写了一些入门代码来帮助你。

Not everyone will do this for you and I rarely do it as well.不是每个人都会为你做这件事,我也很少这样做。 We do this because we believe that offering the quick and dirty solution teaches people nothing.我们这样做是因为我们相信提供快速而肮脏的解决方案不会教给人们任何东西。

Therefore I would appreciate that you take a look at these links below to learn about why my code does what it does.因此,如果您查看下面的这些链接以了解我的代码为什么会这样做,我将不胜感激。 :) :)

https://www.w3schools.com/js/js_variables.asp https://www.w3schools.com/js/js_variables.asp

https://www.w3schools.com/jsref/jsref_split.asp https://www.w3schools.com/jsref/jsref_split.asp

https://www.w3schools.com/js/js_switch.asp https://www.w3schools.com/js/js_switch.asp

https://www.w3schools.com/js/js_arrays.asp https://www.w3schools.com/js/js_arrays.asp

var version = "10";

bot.on("message", message => {
    let args = message.split(" ");
    if(args.length === 0) {
        //send error no arguments
        return;
    }
    switch(args[0]) {
        case 'test':
            messages.channel.send(version.toString());
            break;
        case 'version':
            if(args.length < 2) {
                //send error too short message
            } else {
                version = args[1];
            }
            break;
        default:
            //send not found
            break;
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM