【发布时间】:2021-07-07 11:43:59
【问题描述】:
我的不和谐机器人发送了错误的嵌入消息。这是一个拥抱命令,如果有人没有提及某人,机器人会在频道中发送一条错误消息,内容如下:请提及有效用户!我想将此消息作为嵌入发送,但是它无法正常工作。每次我在不提及某人的情况下使用该命令时,我的控制台中都不会出现错误。当我提到某人时它可以工作,但它也会发送错误消息。 截图如下:https://i.imgur.com/bcnS1Yb.png
我的代码:
const Discord = require('discord.js');
const prefix = require('../config.json');
const hugGif = require('./Huggifs.json');
module.exports = {
name: "hug",
description: "Posts a hug gif.",
aliases: ['hug'],
execute(client, message, args) {
if (!message.mentions.users.first())
return message.channel.send();
const aembed = new Discord.MessageEmbed()
.setColor('BLUE')
.setTitle(`**Please mention a valid user!**`)
message.channel.send(aembed);
const gif = hugGif[Math.floor(Math.random() * hugGif.length)];
const embed = new Discord.MessageEmbed()
.setColor('BLUE')
.setTitle(`${message.author.username} hugs ${message.mentions.users.first().username}!`)
.setImage(gif)
.setFooter( `Requested by ${message.author.username}`)
.setTimestamp()
message.channel.send(embed);
},
};
请帮帮我,谢谢!
【问题讨论】:
-
if (!message.mentions.users.first()) return message.channel.send();???这不是 if 语句的推荐结构。另外,如果您希望获得帮助,请分享您遇到的错误。你为什么叫.send()空?
标签: javascript node.js discord discord.js embed