簡體   English   中英

無法在 discord.js 中發送嵌入?

[英]Can't send embeds in discord.js?

當我嘗試將 Embed 發送到 TextChannel 時:

const embed = new Discord.MessageEmbed()
    .setTitle('Some title')

msg.channel.send(embed);

它只是給了我這個錯誤:

(node:76224) UnhandledPromiseRejectionWarning: TypeError: fields.flat is not a function
    at Function.normalizeFields (C:\Users\user\Desktop\code\jbot\node_modules\discord.js\src\structures\MessageEmbed.js:450:8)
    at MessageEmbed.setup (C:\Users\user\Desktop\code\jbot\node_modules\discord.js\src\structures\MessageEmbed.js:78:91)
    at new MessageEmbed (C:\Users\user\Desktop\code\jbot\node_modules\discord.js\src\structures\MessageEmbed.js:18:10)
    at embedLikes.map.e (C:\Users\user\Desktop\code\jbot\node_modules\discord.js\src\structures\APIMessage.js:166:40)
    at Array.map (<anonymous>)
    at APIMessage.resolveData (C:\Users\user\Desktop\code\jbot\node_modules\discord.js\src\structures\APIMessage.js:166:31)
    at TextChannel.send (C:\Users\user\Desktop\code\jbot\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:166:62)
    at Object.module.exports.execute (C:\Users\user\Desktop\code\jbot\commands\help.js:36:17)
    at Client.client.on.message (C:\Users\user\Desktop\code\jbot\index.js:38:42)
    at Client.emit (events.js:198:13)
(node:76224) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:76224) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

我有最新版本的 discord.js。 而且我也嘗試重新安裝 discord.js 但它沒有解決問題。

請將 NodeJS 更新到至少 12 版,這將解決您的問題

當我嘗試將Embed發送到TextChannel時:

const embed = new Discord.MessageEmbed()
    .setTitle('Some title')

msg.channel.send(embed);

它只是給我這個錯誤:

(node:76224) UnhandledPromiseRejectionWarning: TypeError: fields.flat is not a function
    at Function.normalizeFields (C:\Users\user\Desktop\code\jbot\node_modules\discord.js\src\structures\MessageEmbed.js:450:8)
    at MessageEmbed.setup (C:\Users\user\Desktop\code\jbot\node_modules\discord.js\src\structures\MessageEmbed.js:78:91)
    at new MessageEmbed (C:\Users\user\Desktop\code\jbot\node_modules\discord.js\src\structures\MessageEmbed.js:18:10)
    at embedLikes.map.e (C:\Users\user\Desktop\code\jbot\node_modules\discord.js\src\structures\APIMessage.js:166:40)
    at Array.map (<anonymous>)
    at APIMessage.resolveData (C:\Users\user\Desktop\code\jbot\node_modules\discord.js\src\structures\APIMessage.js:166:31)
    at TextChannel.send (C:\Users\user\Desktop\code\jbot\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:166:62)
    at Object.module.exports.execute (C:\Users\user\Desktop\code\jbot\commands\help.js:36:17)
    at Client.client.on.message (C:\Users\user\Desktop\code\jbot\index.js:38:42)
    at Client.emit (events.js:198:13)
(node:76224) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:76224) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

我有最新版本的discord.js。 而且我也嘗試過重新安裝discord.js,但沒有解決問題。

首先使用最新版本的Node.JS(我用的是14),

使用那個

const Discord = require("discord.js");
const client = new Discord.Client();

client.on("ready", () => {
   console.log(`${client.user.tag} I am here!`);
});
client.on("message", async message => {  // If no want to use async delete it
   if(message.content === ".embed") {
      const embed = new Discord.MessageEmbed()
      embed.setTitle("This is a embed!")
      embed.setDescription(`That is an embed [https://stackoverflow.com](StackOverFlow)`)
      embed.addFields(
            { name: "FIeld Name", value: "true inline", inline: true }
            { name: "Field Name", value: "true inline", inline: true }
            { name: "FIeld Name", value: "false inline", inline: false }
            { name: "Field Name", value: "false inline", inline: false }
      )
            embed.setFooter("Footer Name")
            embed.setAuthor("options")
            embed.setImage("image_Link");
            await message.channel.send(embed);  // If you are not using async delete await
}
});

玩得開心你的機器人!

這僅適用於 Discord.JSv12 要安裝它,請在您的 cmd / linux 終端中輸入npm install discord.js@v12

首先安裝 Node.js 和 Discord.js 最新版本並編寫代碼!

const discord = require("discord.js") //i define discord.js
const your embed name = new discord.MessageEmbed() .setTitle() .setDescription() msg.channel.send(embed);

你可以問我任何問題我有空

請確保您的 node.js 版本至少為 v12。 這很可能會解決您的問題。 如果您使用的是 ubuntu,這里是升級到 v12 的指南:

指導

第 4 步可跳過

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM