[英]How to edit embed field value in Discord.js V13
所以我試圖在嵌入中編輯一個字段。 獲取的嵌入看起來像這樣:
MessageEmbed {
type: 'rich',
title: null,
description: null,
url: null,
color: 5763719,
timestamp: null,
fields: [
{ name: 'Suggestie', value: 'test1', inline: false },
{ name: 'Status', value: 'Open', inline: true },
{ name: 'ID', value: 'SPogb', inline: true },
{ name: 'User ID', value: '291272018773671937', inline: true },
{
name: 'Opmerking van staff:',
value: 'Geen opmerking',
inline: false
}
],
thumbnail: null,
image: null,
video: null,
author: {
name: 'Nigel#7777',
url: undefined,
iconURL: 'https://cdn.discordapp.com/avatars/291272018773671937/b2637472f4502b2b2280b6302d3f666c.webp',
proxyIconURL: 'https://images-ext-1.discordapp.net/external/I_MfeMd6YbK_NxsY_kG-k7P6hiytpXx3tNk9ZJdd9lg/https/cdn.discordapp.com/avatars/291272018773671937/b2637472f4502b2b2280b6302d3f666c.webp'
},
provider: null,
footer: null
}
我正在嘗試將 Status 字段值從 Open 編輯為 Approved,但我不知道如何實現。 我目前有:
const kanaal = interaction.guild.channels.cache.get(config.kanalen.suggestieKanaal)
const ID = interaction.options.getString('id');
let correcteSuggest;
kanaal.messages.fetch({limit: 50}).then(messages => {
const botMessages = messages.filter(msg => msg.author.bot);
botMessages.forEach(msg => {
if(msg.embeds[0].fields[2].value === interaction.options.getString('id')) {
correcteSuggest = msg;
}
})
console.log(correcteSuggest.embeds[0].fields)
// correcteSuggest.edit(embeds[0].fields[1] = ({name: "Status", value: "Approved", inline: true}))
// const editedEmbed = new Discord.MessageEmbed(correcteSuggest.embeds[0]).fields[3]
})
我嘗試過但似乎沒有用的評論內容。 我已經看到其他人獲得嵌入並執行 like.setDescription,但我不知道這將如何與 .setField 一起使用,因為有不止一個字段。
通過執行以下操作解決此問題:
correcteSuggest.embeds[0].fields.find(f => f.name === "Status").value = "Approved";
correcteSuggest.edit({embeds: [correcteSuggest.embeds[0]]})
您編輯嵌入的邏輯是正確的,但方式是錯誤的。 Discord.JS 實際上不只更新一個字段,它更新整個消息,因此我們需要將方式更改為全新的 MessageEmbed。
const kanaal = interaction.guild.channels.cache.get(config.kanalen.suggestieKanaal)
const ID = interaction.options.getString('id');
let correcteSuggest;
kanaal.messages.fetch({
limit: 50
}).then(messages => {
const botMessages = messages.filter(msg => msg.author.bot);
botMessages.forEach(msg => {
if (msg.embeds[0].fields[2].value === interaction.options.getString('id')) {
correcteSuggest = msg;
}
})
if (correcteSuggest.embeds[0]) {
const editedEmbed = new Discord.MessageEmbed(correcteSuggest.embeds[0]);
editedEmbed.fields[1].value = "Approved";
correcteSuggest.edit({
embeds: [editedEmbed]
});
}
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.