为什么在我运行命令时终端返回“无法发送空消息”?

我正在尝试执行口袋妖怪命令,但由于某种原因,它返回为.这是代码,我希望这个平台能帮助我解决我的问题。UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message


const rand = Math.floor(Math.random() * 802);

const poke = rand > 0 ? rand : Math.floor(Math.random() * 802);

const pokem = pokemon[poke];


const embed = new Discord.MessageEmbed()

  .setTitle("🕰️ Time is ticking! You have 15 seconds to answer | WHO'S THAT POKEMON?!")

  .setColor(colored[~~(Math.random() * colored.length)])

  .setAuthor(message.member.displayName, message.author.displayAvatarURL())

  .setImage(pokem.imageURL);


const msg = await message.channel.send(embed);

const filter = m => m.author.id === message.author.id;

const attempts = await msg.channel.awaitMessages(filter, { time: 15000, max: 1 });


if (!attempts || !attempts.size) {

  msg.delete();

  const embed = new Discord.MessageEmbed()

    .setTitle("🕰️ Time is up!")

    .setColor(colored[~~(Math.random() * colored.length)])

    .setDescription(`Ba-Baka! Your 15 seconds is over. It was \`${pokem.name}\`.`);


  return message.channel.send(embed);

}


const answer = attempts.first().content.toLowerCase();


if (answer === pokem.name.toLowerCase()) {

  await msg.edit({ embed: null });

  let embed = new Discord.MessageEmbed()

    .setTitle("<a:done:707045670661652481> Correct")

    .setColor(colored[~~(Math.random() * colored.length)])

    .setDescription(`Yatta! Well done, \`${pokem.name}\` was correct.`);


  return message.channel.send(embed);

}

await msg.edit({ embed: null });

embed = new Discord.MessageEmbed()

  .setTitle("<a:error:707045703003668521> Incorrect")

  .setColor(colored[~~(Math.random() * colored.length)])

  .setDescription(`Ba-Baka! You answered incorrectly, It was \`${pokem.name}\`.**`);


return message.channel.send(embed);


汪汪一只猫
浏览 90回答 1
1回答

蝴蝶刀刀

您正在使用 编辑消息。由于消息只有嵌入,这将删除嵌入,因此没有要编辑消息的内容。{embed: null}如果我正确解释代码,您希望更新嵌入,因此请使用以下内容:// Using let here so that embed can be reassigned laterlet embed = new Discord.MessageEmbed()&nbsp; &nbsp; &nbsp;.setTitle("🕰️ Time is ticking! You have 15 seconds to answer | WHO'S THAT POKEMON?!")&nbsp; &nbsp; &nbsp;.setColor(colored[~~(Math.random() * colored.length)])&nbsp; &nbsp; &nbsp;.setAuthor(message.member.displayName, message.author.displayAvatarURL())&nbsp; &nbsp; &nbsp;.setImage(pokem.imageURL)// rest of code...if (answer === pokem.name.toLowerCase()) {&nbsp;let embed = new Discord.MessageEmbed()&nbsp; &nbsp; .setTitle("<a:done:707045670661652481> Correct")&nbsp; &nbsp; .setColor(colored[~~(Math.random() * colored.length)])&nbsp; &nbsp; .setDescription(`Yatta! Well done, \`${pokem.name}\` was correct.`);&nbsp; // {embed} is shorthand for {embed: embed}&nbsp; await msg.edit({embed});&nbsp; return message.channel.send(embed);}// Instead of reassigning to embed, you could also create a new variableembed = new Discord.MessageEmbed()&nbsp; &nbsp; .setTitle("<a:error:707045703003668521> Incorrect")&nbsp; &nbsp; .setColor(colored[~~(Math.random() * colored.length)])&nbsp; &nbsp; .setDescription(`Ba-Baka! You answered incorrectly, It was \`${pokem.name}\`.**`);await msg.edit({embed});
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript