javascript - discord.js - 我需要有关配置文件命令的帮助
问题描述
所以,我为我的机器人创建了一个配置文件命令,但我想添加第二个参数。我想做的命令是 "/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);
}
}
解决方案
一个快速的好方法来做你想做的事,
//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"]
}
推荐阅读
- r - 如何将聊天数据向量转换为数据框或矩阵
- python - 在左右(顶部和底部)启用散景 y (x) 轴刻度
- python - 在 Python 中读取 CSV 时出现 ValueError
- c# - 并发发送多个请求时等待 REST 调用完成的死锁问题
- c++ - 如何定义一些可以从(+)运算符的运算符重载范围内访问的函数?
- shell - 为什么使用“./”和“bash”运行脚本结果不同?
- flutter - Flutter:从手机图库中预览一张或多张图片?
- php - 在foreach循环内以小时为单位获取两个日期之间的差异
- php - 有没有理由用自己的元素之一覆盖数组变量?
- facebook-graph-api - ID 为“”的 Facebook 对象不存在 - 用于公开的现有图片