javascript - 从嵌入对象 DiscordJS 中删除 1 个元素
问题描述
我一直在尝试编写一个将 1 个嵌入从 1 个频道复制到另一个频道的机器人。
但是在将其发布到另一个频道之前,我希望它从嵌入对象中删除 1 个元素。
我目前如何拥有它:
client.on("message", (message) => {
if (message.channel.id == channel1) {
const embed = message.embeds[0];
var params = {
embeds: [embed],
};
fetch("WEBHOOK URL", {
//send channel 2
method: "POST",
headers: {
"Content-type": "application/json",
},
body: JSON.stringify(params),
}).then((res) => {});
}
});
如您所见,我直接使用 message.embeds[0]。
所以我什至不知道是否可以从中删除 1 个元素,例如页脚文本。
如果有人知道它是否可以完成,请说出来。
感谢您的阅读。
编辑:
会不会是这样的:
const embed = message.embeds[0];
embed.footer.text = [];
// or
embed.footer[0].text
解决方案
您可以使用delete
运算符从对象中删除属性。
const embed = message.embeds[0];
if (!embed) return;
delete embed.footer;
message.channel.send({
content: "Footer removed!",
embeds: [embed]
});
请注意,您不能只删除text
属性并保留图标。text
如果没有属性,页脚将不会显示。
这些也有效:
// Remove only text from footer (footer won't be visible including icon)
embed.footer.text = "";
// Or
embed.footer = {};
// Or
embed.footer = null;
// Or ...
推荐阅读
- powershell - 使用 Gradle 调用 powershell 脚本
- build - 在命令触发的 docker-compose build 之前执行一些 bash 脚本
- apache-camel - 如何解决 java.lang.NoClassDefFoundError: org/apache/camel/impl/DefaultComponent?
- css - 宽度属性会影响清除吗?
- python - 重塑数据框:列到行
- java - 说在 String 变量中可以存储所有 ASCII 符号是否正确?
- javascript - jQuery:如何克隆包含 p5 画布的 div?
- powershell - 获取连接属性名称
- npm - NPM 的 package-lock.json 中的层次结构代表什么?
- python - QFont.setFamily() 不适用于自定义字体