【发布时间】:2020-11-12 22:49:06
【问题描述】:
是否可以更改嵌入中的图像?我正在尝试重新创建我在 reddit 上看到的“etch-a-sketch”机器人,并且想知道它是如何完成的。这是我到目前为止所尝试的: 这是在制作图像的函数内部:
//code that draws the etch-a-sketch
const etchembed = new Discord.MessageEmbed()
.setAuthor(`${message.author.username}`, `${message.author.displayAvatarURL()}`)
.setTitle('???? Etch-A-Sketch ????')
.setColor("#f66868")
.setFooter(`${client.user.username}`, `${client.user.displayAvatarURL()}`)
//n is a variable that increases by 1 every time the function is run
.attachFiles([new Discord.MessageAttachment(canvas.toBuffer(), `etch${n}.png`)])
.setImage(`attachment://etch${n}.png`)
.setTimestamp();
return etchembed
在主命令文件中,我在等待函数返回后执行此操作:
message.edit(newetchembed)
所有这些只是将图像移到嵌入之外。我做错了吗?
编辑 1:
我尝试将 message.edit(...) 更改为 message.channel.send(...) 并发送一个带有正确图像的新嵌入。当我尝试使用 message.edit 时,它只是出于某种原因将图像移到嵌入之外。
编辑 2:
我做了更多测试,我开始认为这只是 discord 或 discord.js 出了点问题。这是因为当我记录文件附件和图像时,一切正常:
embed 1: [
MessageAttachment {
attachment: < Buffer 89 50 4e 47 0 d 0 a 1 a 0 a 00 00 00 0 d 49 48 44 52 00 00 01 94 00 00 01 2 c 08 06 00 00 00 e4 5 c 45 b8 00 00 00 06 62 4 b 47 44 00 ff 00 ff 00 ff a0 bd a7...1167 more bytes > ,
name: 'etch_1595840597644.png'
}
] {
url: 'attachment://etch_1595840597644.png'
}
embed 2: [
MessageAttachment {
attachment: < Buffer 89 50 4e 47 0 d 0 a 1 a 0 a 00 00 00 0 d 49 48 44 52 00 00 01 94 00 00 01 2 c 08 06 00 00 00 e4 5 c 45 b8 00 00 00 06 62 4 b 47 44 00 ff 00 ff 00 ff a0 bd a7...1167 more bytes > ,
name: 'etch_1595840607390.png'
}
] {
url: 'attachment://etch_1595840607390.png'
}
如您所见,消息嵌入具有不同的图像附件,因此我不确定为什么它只是将原始图像移到嵌入之外而不是附加新图像。 This is what it looks like.
另一件事是,当我发送新消息而不是编辑时,它会发送正确的图像。
【问题讨论】:
标签: canvas discord discord.js