Discord.js Args split string code example
Example 1: split a message
const message = 'This is a test'
var args = message.split(' ');
console.log(args[0]) // Responds "This"
console.log(args[1]) // Responds "is"
console.log(args[2]) // Responds "a"
console.log(args[3]) // Responds "test"
Example 2: args slice discord.js
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if (command === "RandomCommand") {
let firstArgs = args[0]; //first argument
let secondArgs = args[1]; //second argument
if (firstArgs && secondArgs) { //check if the args are existing
message.channel.send(firstArgs, secondArgs) //send the value of the args
}
}