Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
360 views
in Technique[技术] by (71.8m points)

javascript - Discord.JS: Multiple args for one variable

i`m try to make this:

!send <id> message who sended (message who sended is 3 args but i'm need one)

Who send arguments after message ID (args[0]) for everyone who reacted to message in DM. How make from arguments after first argument, next argument?

        const messageID = parseInt(args[0]);
        var messageContent = message.substring(1).split(' ');

I`m try this, but I'm not sure it will work.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you want to join multiple arguments together, you can use splice and join

To begin, we need to define it as a new variable equal to args

messageable = args

Next, use splice to make a new array out of the index. If you want to make it so it is everything after the <id>, remove ,5, so .splice(2)

messageable = args.splice(2,5)

Finally, join it into a string using join, adding a space in-between the arguments

messageable = args.splice(2,5).join(" ")

With this, messageable should look like "message who sended"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...