Why my args[1] doesn't work in this case in discord

DdankDdum

The code works normal for args[0] but doesn't work for args[1]. Can you guys explain this for me or give me a source that I can find out my mistake? Thanks for your help

bot.on('message', message =>{

    let args = message.content.substring(PREFIX.length).split("  ");

    switch(args[0]){
        case 'ping':
            message.reply('Pong!');
            break;
        case 'website':
            message.reply('www.facebook.com')
            break;
        case 'info':
            if(args[1] === 'version'){
                message.reply('Version ' + version);
            }else{
                if(args[1] === 'author'){
                    message.reply('Vikoaz');
               }else{
                   message.reply('Invalid')
               }
            }
        break;
        case 'clear':
            if(!args[1]) return message.reply('Error')
            message.channel.bulkDelete(args[1]);
        break;


    }

When I write !info version in Discord the bot doesn't reply Version + version. Nothing happens. If just !info the bot replies Invalid.

Example

cherryblossom

There are 2 spaces here: .split(" "). Make that 1 space:

let args = message.content.substring(PREFIX.length).split(" ");

With 2 spaces, if message.content is '!info version' args would be ['info version'], which is why it wasn't working.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Why my xpath doesn't work

分類Dev

Why doesn't my SetLength work?

分類Dev

Iptables: why my redirection doesn't work?

分類Dev

Why doesn't my SUMIF formula work?

分類Dev

Why doesn't my InStr Work?

分類Dev

unblind click doesn't work in my case to remove click event

分類Dev

Why doesn't stdin from a file work in case of scp?

分類Dev

Why does my first snippit work, but my second doesn't?

分類Dev

Why kill -9 -1 doesn't work?

分類Dev

Why doesn't auto complete work in my shell?

分類Dev

My spawning system doesn't work and I dont know why

分類Dev

Why doesn't my implementation of linked list work?

分類Dev

Why my router navigate function doesn't work in angular 8?

分類Dev

why does my window doesn't work for on_draw?

分類Dev

Why my simple filter in Jersey doesn't work?

分類Dev

Why doesn't anything in my if-else work?

分類Dev

Why doesn't my ~/.bash_profile work?

分類Dev

Why my data-binding doesn't work?

分類Dev

Why my trash icon doesn't work in 12.04 LTS?

分類Dev

Why doesn't my HTML structure work with the CSS Grid layout?

分類Dev

Why doesn't my jQuery Mobile code work?

分類Dev

My ShaderProgram doesn't work

分類Dev

Why isEOF doesn't work?

分類Dev

Why json doesn´t work?

分類Dev

Why doesn't z-index: -1 work in this instance?

分類Dev

My second endpoint doesn't work for node-js API, why?

分類Dev

Why my Vigenere encryption function for small letters doesn't work correctly?

分類Dev

Why doesn't zurb foundation off-canvas work in my project?

分類Dev

Why doesn't my program work with float variables, but it does with int variables?