我正在尝试执行discord.js头像命令,并且提及部分无法正常工作 [英] I am trying to make a discord.js avatar command, and the mentioning portion doesn't work correctly
问题描述
我的Discord机器人中有一个化身命令.当用户使用h.avatar
时,它会输出其头像,效果很好.每当他们尝试使用h.avatar @user
时,都不会发生任何事情.
这是我的代码:
I have an avatar command in my discord bot. When the user uses h.avatar
, it outputs their avatar, which works fine. Whenever they try to use h.avatar @user
, nothing happens.
Here is my code:
} if (message.content.startsWith(config.prefix + "avatar")) {
if (!message.mentions.users.size) {
const avatarAuthor = new Discord.RichEmbed()
.setColor(0x333333)
.setAuthor(message.author.username)
.setImage(message.author.avatarURL)
message.channel.send(avatarAuthor);
let mention = message.mentions.members.first();
const avatarMention = new Discord.RichEmbed()
.setColor(0x333333)
.setAuthor(mention.user.username)
.setImage(mention.user.avatarURL)
message.channel.send(avatarMention);
推荐答案
您有一个检查if (!message.mentions.users.size) {
,该检查使该命令仅在您不提及某人时才运行.您需要在代码中使用else {
或执行以下操作:
You have a check if (!message.mentions.users.size) {
which makes the command run only if you do not mention somebody. You either need to use an else {
in your code or do:
if (message.content.startsWith(config.prefix + 'avatar')) {
const user = message.mentions.users.first() || message.author;
const avatarEmbed = new Discord.RichEmbed()
.setColor(0x333333)
.setAuthor(user.username)
.setImage(user.avatarURL);
message.channel.send(avatarEmbed);
}
const user = message.mentions.users.first() || message.author;
试图获取提到的用户,但是如果找不到任何人,它将使用作者的个人身份.
The const user = message.mentions.users.first() || message.author;
tries to get the user that was mentioned but if it does not find anyone it will use the author's used.
这篇关于我正在尝试执行discord.js头像命令,并且提及部分无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!