discord.js-我需要个人资料命令的帮助

时间:2018-07-02 16:31:34

标签: javascript discord.js

因此,我为我的机器人创建了一个配置文件命令,但我想添加第二个参数。 我要执行的命令是“ / profile [要搜索的用户名]”,但是我现在不知道如何执行该命令。

如果您能帮助我,我将不胜感激。

这是代码:

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);
       }
    }

1 个答案:

答案 0 :(得分:0)

一种快速好的方法来做您想要的事情,

//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});    
}

您还可以通过执行以下操作来检查(/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"]

}