gpt4 book ai didi

canvas - 如何在嵌入的 discord 中编辑图像?

转载 作者:行者123 更新时间:2023-12-04 09:24:04 44 4
gpt4 key购买 nike

是否可以更改嵌入内的图像?我正在尝试重新创建一个我在 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.

另一件事是当我发送新消息而不是编辑时它会发送正确的图像。

最佳答案

是的,这是可能的!

  1. 发送包含新图像的新消息。 (您可以将其发送到专用于此目的的特定 channel /服务器)。

  2. 获取附加图片的 URL。

  3. 在要编辑的嵌入中,将图像 url 更改为新图像的 url。

参见 this answer通过 Fahadmy similar question 下.

除了第 1 步之外,您还可以创建一个网络服务器或找到一个 API,这样您就可以自己托管新图像。然后您还可以编辑嵌入的图像 URL 以匹配它。

关于canvas - 如何在嵌入的 discord 中编辑图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63050380/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com