【问题标题】:discord.js - I need help for a profile commanddiscord.js - 我需要有关配置文件命令的帮助
【发布时间】:2018-07-04 03:12:38
【问题描述】:

所以,我为我的机器人创建了一个配置文件命令,但我想添加第二个参数。 我想做的命令是 "/profile [username to search]" ,但我现在不知道该怎么做。

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

代码如下:

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

【问题讨论】:

标签: javascript discord.js


【解决方案1】:

做你想做的事的快速好方法,

//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"]

}

【讨论】:

    猜你喜欢
    • 2019-05-17
    • 2015-04-12
    • 1970-01-01
    • 2011-05-24
    • 2019-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多