亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么在我運行命令時終端返回“無法發送空消息”?

為什么在我運行命令時終端返回“無法發送空消息”?

汪汪一只貓 2022-08-04 16:05:06
我正在嘗試執行口袋妖怪命令,但由于某種原因,它返回為.這是代碼,我希望這個平臺能幫助我解決我的問題。UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty messageconst 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);
查看完整描述

1 回答

?
蝴蝶刀刀

TA貢獻1801條經驗 獲得超8個贊

您正在使用 編輯消息。由于消息只有嵌入,這將刪除嵌入,因此沒有要編輯消息的內容。{embed: null}


如果我正確解釋代碼,您希望更新嵌入,因此請使用以下內容:


// Using let here so that embed can be reassigned later

let 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)


// rest of code...


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

 let embed = new Discord.MessageEmbed()

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

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

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

  // {embed} is shorthand for {embed: embed}

  await msg.edit({embed});

  return message.channel.send(embed);

}

// Instead of reassigning to embed, you could also create a new variable

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}\`.**`);

await msg.edit({embed});


查看完整回答
反對 回復 2022-08-04
  • 1 回答
  • 0 關注
  • 102 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號