I'm writing a small bot to help manage the reviewing of various content. This involves a slash command to start a review, after which a message is posted as an 'overview' in the main channel and people can talk about the content in a thread attached to that message. The user can then update the message in the main channel with other slash commands, of which some of that content is images.
I'm in the process of refactoring it, and I can't get an image to be embedded to the post as if you attached it to the post while writing it.
This is a setup for receiving and storing an image, which appears to work fine:
import * as discord from "discord.js"
import { updateDescriptions, checkReviewPermissions } from "../utils"
const data = new discord.SlashCommandBuilder()
.setName('update-pathing-preview')
.setDescription('Update pathing preview of the map')
.addAttachmentOption(option =>
option.setName('pathing-preview-image')
.setDescription('The pathing preview usually generated with the map editor')
.setRequired(true))
const execute = async (interaction: discord.Interaction ) => {
if (!interaction.isChatInputCommand()) {
return;
}
await interaction.reply({ content: 'Updating pathing preview...', ephemeral: true })
const permissions = await checkReviewPermissions(interaction)
if (!permissions) {
await interaction.editReply({ content: 'Updating pathing preview... failed! Something went wrong' })
return
}
permissions.review.imagePathing = {
attachment: interaction.options.getAttachment('pathing-preview-image')!.attachment,
name: 'Pathing preview',
description: 'The pathing preview usually generated with the map editor',
}
updateDescriptions(permissions.review, permissions.overviewMessage, permissions.detailedMessage, permissions.reviewsMessage)
await interaction.editReply({ content: 'Updating pathing preview... done!' })
}
module.exports = { data, execute };
And this is what I'm trying to update the overview message:
const attachments : discord.AttachmentPayload[] = [ ]
if (review.imagePreview) {
attachments.push(review.imagePreview)
}
if (review.imagePathing) {
attachments.push(review.imagePathing)
}
message.edit({
content: `${title} \r\n${preview}\r\n${pathing}\r\n\r\nLast update: ${new Date().toLocaleDateString()}`,
embeds: attachments
})
It shows as an attachment / embed where the name and description exists but the image itself appears to have been lost. I tried adding it as a file, but then the image is turned into a download. I also tried adding it as an attachment, but I don't understand how to construct the JSONEncode<Attachment> type that it requires.
Any ideas on how to properly embed that image?