[英]Discord.js v13 embed is empty when sent to a channel
當我想向頻道發送嵌入時,它只會發送一條空消息。
圖片:
const { MessageEmbed } = require("discord.js");
const embed = new MessageEmbed()
.setTitle("Title")
.setDescription("Description");
console.log(embed);
return message.channel.send({ embeds: [embed] });
const Discord = require("discord.js");
const embed = new MessageEmbed()
embed.setTitle("Title")
embed.setDescription("Description");
console.log(embed);
return message.channel.send(embed);
試試這個我的 discord 否則 NullTopdog#9865
我認為您只是對返回的工作方式感到困惑,盡管在 javascript 中您可以返回諸如message.channel.send()
之類的函數,但您不應該這樣做。 您可以返回返回函數、變量和非返回函數(盡管返回非返回函數毫無意義)。 簡而言之,您可以使用return
關鍵字來結束 function 的執行並將一個變量發送到任何稱為 function 的變量,例如,如果您想要一個隨機數生成器,
function ReturnOne(){
return 1 //Simply returns 1
}
function MakeRandom(Maximum){ // The Maximum variable is used to define the highest amount we want
return randomInt(Maximum)// randomint is a function in Node.js that returns a random number, so it is a returnable function retuning to our function, MakeRandom()
}
console.log(ReturnOne()) // Runs the random function above and returns 1
console.log(MakeRandom(99)) // Runs the MakeRandom function and returns a random number`
Output 第一次運行
1
34
Output 第二輪
1
78
足夠的閑聊,(盡管您應該在上面閱讀)這段代碼應該可以工作,
const { MessageEmbed } = require("discord.js")
const embed = new MessageEmbed()
.setTitle("Title")
.setDescription("Description")
console.log(embed) // I don't understand why you would want to console this as it will just output the json data, but ill keep it
message.channel.send({ embeds: [embed] }) // Removed the return
我犯了一個錯誤。
我在 Discord 的用戶設置中關閉了“鏈接預覽”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.