I
I
Ilya Zholudev2021-02-22 17:59:24
Node.js
Ilya Zholudev, 2021-02-22 17:59:24

How to pull the argument after the given flags?

Good day,
my problem is that I want to pull out a line after the flag,
as it looks like for me:

if(message.content.startsWith("/bug")) { 
        var Author = message.author;
        var Channel = message.channel;
        var title = message.content.split('-t');
        var bug = message.content.split('-p');  
        var embed = new Discord.MessageEmbed() 
           .setTitle("Баг")
           .setColor(RColor) 
           .setAuthor(Author)
           .addFields(
            {name: "Заглавие:", value: `${}`},
            {name: "Баг:", value: `${}`},
            {name: '\u200B', value: '\u200B'},            
            {name: "ПО:\u200B", value: `${}`, inline: true},
            {name: "Лаунчер:\u200B", value: `${}`, inline: true}
            
           )
           .addField("Версия:\u200B", `${title()}`, true)
           
        message.channel.send(embed);
    }

My goal is to create a command in which the specified text between the -t and -p flags would fall into the form and be sent to another discord channel, example command:
/bug -t Some title -p Some problem
It is necessary that the bot put the text after flag '-t' by analogy with '-p'
I know that there are more places for flags than I wrote here, but the main thing for me is to understand how you can pull out the text after the flag.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya Zholudev, 2021-02-22
@Astroreen

Well, after I sat for a while and thought, I wrote this code, and it worked:

if (message.content.startsWith("/bug"))
    { 
        var Author = message.author;
        var Channel = message.channel;
        Ttitle = function () {
            const title = message.content.split('-t');
            const Rbug = title[1].split('-b');
            return Rbug[0];
        }
        Tbug = function () {
            const Textbug = message.content.split('-b');
            const RPO = Textbug[1].split('-p');
            return RPO[0];
        }
        TPO = function () {
            const TextPO = message.content.split('-p');
            const Rlauncher = TextPO[1].split('-l');
            return Rlauncher[0];
        }
        Tlauncher = function () {
            const Textlauncher = message.content.split('-l');
            const Rversion = Textlauncher[1].split('-v');
            return Rversion[0];
        }
        TVersion = function () {
            const Textversion = message.content.split('-v');
            return Textversion[1];
        }
        var embed = new Discord.MessageEmbed() 
           .setTitle("Баг")
           .setColor(RColor()) 
           .setAuthor(Author)
           .addFields(
            {name: "Заглавие:", value: `${Ttitle()}`},
            {name: "Баг:", value: `${Tbug()}`},
            {name: '\u200B', value: '\u200B'},            
            {name: "ПО:\u200B", value: `${TPO()}`, inline: true},
            {name: "Лаунчер:\u200B", value: `${Tlauncher()}`, inline: true}
            
           )
           .addField("Версия:\u200B", `${TVersion()}`, true)
           
        message.channel.send(embed);
    }

A
Alexander, 2021-02-22
@Alexandre888

https://discordjs.guide/creating-your-bot/commands...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question