discord.js - I need help for a profile command


discord.js - I need help for a profile command



So, I've created a profile command for my bot but I wanna add an second argument.
The command that I wanna make is "/profile [username to search]" , but I don't now how to do it.



If you can help me, I'll appreciate this.



Here is the code:


if (message.content === '/profile') {
let botembed = new Discord.RichEmbed()
.setTitle("**__Exoly User Profile__**")
.setTimestamp(new Date())
.setColor("#4286f4")
.setFooter("Exolia", `${bot.user.avatarURL}`)
.setThumbnail(`${message.author.avatarURL}`)
.addField("Username :", `${message.author.username}`, inline = true)
.addField("Exolytes :", "|---|", inline = true)
.addField("Played Time :", "|---|", inline = true)
.addField("Faction :", "Armada", inline = true);
if (shouldResponseTo(message)) {
message.delete()
return message.channel.send(botembed);
}
}





It's worth adding what code you have already so there's a something to reference from
– John
Jul 2 at 16:42





Possible duplicate of Discord.js Arguments With Spaces
– John
Jul 2 at 16:50




1 Answer
1



A quick nice way to do what you want,


//Checks if it starts with (/profile)
if(message.content.startsWith(`/profile`)){
//Defines the user that needs to be searched to be either the user pinged OR the user that called the command
let user = message.mentions.users.first(); || message.author;
let embed = new Discord.RichEmbed()
.setTitle(`Profile`);
.setDescription(`Profile of ${user.username}`);
//Note: .send(embed) is allowed but not recommended and it's easier and safer todo .send({embed}) or in your case .send({embed:botembed})
message.channel.send({embed});
}



You could also check what was said AFTER (/profile) by doing:


(/profile)


let args = message.content.split(` `);
if(args[0]===`/profile`){
args.shift();
//args is now all the arguments that was put in after (/profile)

//So a message (/profile @user page 3)
//args would equal ["@user", "page", "3"]

}






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

PHP contact form sending but not receiving emails

PHP parse/syntax errors; and how to solve them?

iOS Top Alignment constraint based on screen (superview) height