[英]not working command when user is mentioned
I have a piece of code that returns a Rich Embed with the Avatar of the mentioned user or the message author if it hasn't got a mention, the code works without mentioning but it doesn't work when mentioning someone.我有一段代码,如果没有提及,则返回带有提到的用户或消息作者的头像的 Rich Embed,代码在没有提及的情况下工作,但在提及某人时不起作用。 (No error in the console)
(控制台没有错误)
if (message.content === prefix + "avatar") {
const user = message.mentions.users.first()
if (!message.mentions.users.size) {
const Embed = new Discord.MessageEmbed()
.setAuthor(message.author.tag, message.author.avatarURL())
.setColor("#13e2c0")
.setTitle("Avatar")
.setImage(message.author.avatarURL())
message.channel.send(Embed)
}
const Embed = new Discord.MessageEmbed()
.setAuthor(user.tag, user.avatarURL())
.setColor("#13e2c0")
.setTitle("Avatar")
.setImage(user.avatarURL())
message.channel.send(Embed)
}
If there are no users mentions, message.mentions.users.size
, will always be 0, not NULL
or undefined
.如果没有用户提及,则
message.mentions.users.size
将始终为 0,而不是NULL
或undefined
。
if (message.content.toLowerCase().startsWith(prefix + "avatar")) {
const user = message.mentions.users.first() || message.author;
const Embed = new Discord.MessageEmbed()
.setAuthor(user.tag, user.avatarURL())
.setColor("#13e2c0").setTitle("Avatar")
.setImage(user.avatarURL())
return message.channel.send(Embed);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.