MediaGalleryBuilder() error.

I've been encountering this error in which I pass the attachment://file.png in the MediaGalleryBuilder().media.url and send the AttachmentBuilder() in the files array, but it still outputs the error of it not encountering the file sent. As of now, the code is quite unpolished and really scraped on for "testing purposes", but it should work just fine; but, it doesn't.
if(message.content.startsWith('abrirTest')) {
const [command, title, minPlyrs, maxPlyrs, code, roleId] = message.content?.includes(' ')
? message.content?.split(' ')
: [null, null, null, null, null, null];

const startUpAttachment = new AttachmentBuilder(path.join(__dirname, '..', 'assets', 'votación.png'), { name: 'votación.png' });

const component = new StartUpEmbed()
.addAuthor(String(message.member.tag))
.setActualVotes(Number(maxPlyrs))
.setMinVotes(Number(minPlyrs))
.setColor(String('0x80a6d2'))
.setServerInfo(String(code))
.setTitle(String(title))
.setMentionableId(String(roleId))
.setAttachmentString('attachment://votación.png')

console.log(startUpAttachment);
return message.channel.send({
components: [ component.getComponent('attachment://votación.png') ],
flags: [
MessageFlags.IsComponentsV2,
MessageFlags.SuppressEmbeds
],
files: [ startUpAttachment ]
})
}
if(message.content.startsWith('abrirTest')) {
const [command, title, minPlyrs, maxPlyrs, code, roleId] = message.content?.includes(' ')
? message.content?.split(' ')
: [null, null, null, null, null, null];

const startUpAttachment = new AttachmentBuilder(path.join(__dirname, '..', 'assets', 'votación.png'), { name: 'votación.png' });

const component = new StartUpEmbed()
.addAuthor(String(message.member.tag))
.setActualVotes(Number(maxPlyrs))
.setMinVotes(Number(minPlyrs))
.setColor(String('0x80a6d2'))
.setServerInfo(String(code))
.setTitle(String(title))
.setMentionableId(String(roleId))
.setAttachmentString('attachment://votación.png')

console.log(startUpAttachment);
return message.channel.send({
components: [ component.getComponent('attachment://votación.png') ],
flags: [
MessageFlags.IsComponentsV2,
MessageFlags.SuppressEmbeds
],
files: [ startUpAttachment ]
})
}
9 Replies
d.js toolkit
d.js toolkit2d ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Gary
GaryOP2d ago
And this is the class getComponent() method:
getComponent(attachmentUrl) {

const text1 = new TextDisplayBuilder()
.setContent([
`# ${this.content.title}`,
`### <@&${this.content.mentionableRole}>${this.content.placeholderText}`,
`>>> ` +
`┊:checklist:・**Mínimo ${String(this.content.minVotes)} votos.**\n`,
`┊:checklist:・**Código del servidor: \`${this.content.serverCode}\`**\n`,
`┊:checklist:・**Únete al servidor diréctamente [__presionando aquí__](https://policeroleplay.community/join/${this.content.serverCode}).**\n`,
'┊:checklist:・**Reaccionar sin entrar al servidor resultará en una __sanción__.**\n',
'┊:checklist:・[**Reglas del Servidor**](https://normativa-portland-spanish-rp.gitbook.io/normativa-portland-spanish-rp/)'
].join('\n'));

const voteBtn = new ButtonBuilder()
.setLabel(`${this.content.currVotes} / ${this.content.minVotes} Votos.`)
.setStyle(ButtonStyle.Secondary)
.setEmoji('✨')
.setCustomId('vote_open_server');

const section2 = new SectionBuilder()
.addTextDisplayComponents(text1)
.setButtonAccessory(voteBtn);

this.container.addSectionComponents(section2);

this.container.addMediaGalleryComponents(
new MediaGalleryBuilder()
.addItems([
{
media: {
url: attachmentUrl,

}
}
])
)

this.container.addSeparatorComponents(separator => separator.setSpacing(SeparatorSpacingSize.Large).setDivider(true));

const voteButton = new ButtonBuilder()
.setLabel('Presiona acá para votar!')
.setEmoji('✨')
.setStyle(ButtonStyle.Success)
.setCustomId('vote_open_serverrrrr');


const actionRow = new ActionRowBuilder().addComponents(voteButton);

this.container.addActionRowComponents(actionRow);

this.container.addTextDisplayComponents(
new TextDisplayBuilder()
.setContent(
"-# © Todos los derechos reservados, Portland Roleplay"
)
)

console.log(JSON.stringify(this.container.toJSON(), null, 2));
return this.container;
}
getComponent(attachmentUrl) {

const text1 = new TextDisplayBuilder()
.setContent([
`# ${this.content.title}`,
`### <@&${this.content.mentionableRole}>${this.content.placeholderText}`,
`>>> ` +
`┊:checklist:・**Mínimo ${String(this.content.minVotes)} votos.**\n`,
`┊:checklist:・**Código del servidor: \`${this.content.serverCode}\`**\n`,
`┊:checklist:・**Únete al servidor diréctamente [__presionando aquí__](https://policeroleplay.community/join/${this.content.serverCode}).**\n`,
'┊:checklist:・**Reaccionar sin entrar al servidor resultará en una __sanción__.**\n',
'┊:checklist:・[**Reglas del Servidor**](https://normativa-portland-spanish-rp.gitbook.io/normativa-portland-spanish-rp/)'
].join('\n'));

const voteBtn = new ButtonBuilder()
.setLabel(`${this.content.currVotes} / ${this.content.minVotes} Votos.`)
.setStyle(ButtonStyle.Secondary)
.setEmoji('✨')
.setCustomId('vote_open_server');

const section2 = new SectionBuilder()
.addTextDisplayComponents(text1)
.setButtonAccessory(voteBtn);

this.container.addSectionComponents(section2);

this.container.addMediaGalleryComponents(
new MediaGalleryBuilder()
.addItems([
{
media: {
url: attachmentUrl,

}
}
])
)

this.container.addSeparatorComponents(separator => separator.setSpacing(SeparatorSpacingSize.Large).setDivider(true));

const voteButton = new ButtonBuilder()
.setLabel('Presiona acá para votar!')
.setEmoji('✨')
.setStyle(ButtonStyle.Success)
.setCustomId('vote_open_serverrrrr');


const actionRow = new ActionRowBuilder().addComponents(voteButton);

this.container.addActionRowComponents(actionRow);

this.container.addTextDisplayComponents(
new TextDisplayBuilder()
.setContent(
"-# © Todos los derechos reservados, Portland Roleplay"
)
)

console.log(JSON.stringify(this.container.toJSON(), null, 2));
return this.container;
}
As I said, the code its pretty raw as of now, but the methods should output no error at all. This is the AttachmentBuilder's console.log().
AttachmentBuilder {
attachment: 'C:\\Users\\AMD\\Desktop\\portland\\assets\\votación.png',
name: 'votación.png',
description: undefined
}
AttachmentBuilder {
attachment: 'C:\\Users\\AMD\\Desktop\\portland\\assets\\votación.png',
name: 'votación.png',
description: undefined
}
And this is the error I've been getting:
Uncaught exception: DiscordAPIError[50035]: Invalid Form Body
components[0].components[1].items[0].media.url[UNFURLED_MEDIA_ITEM_REFERENCED_ATTACHMENT_NOT_FOUND]: The referenced attachment ("attachment://votación.png") was not found
at handleErrors (C:\Users\AMD\Desktop\portland\node_modules\@discordjs\rest\dist\index.js:748:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (C:\Users\AMD\Desktop\portland\node_modules\@discordjs\rest\dist\index.js:1149:23)
at async SequentialHandler.queueRequest (C:\Users\AMD\Desktop\portland\node_modules\@discordjs\rest\dist\index.js:980:14)
at async _REST.request (C:\Users\AMD\Desktop\portland\node_modules\@discordjs\rest\dist\index.js:1293:22)
at async TextChannel.send (C:\Users\AMD\Desktop\portland\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:195:15) {
requestBody: {
files: [ [Object] ],
json: {
content: undefined,
tts: false,
nonce: undefined,
enforce_nonce: false,
embeds: undefined,
components: [Array],
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: 32772,
message_reference: undefined,
attachments: [Array],
sticker_ids: undefined,
thread_name: undefined,
applied_tags: undefined,
poll: undefined
}
},
rawError: {
message: 'Invalid Form Body',
code: 50035,
errors: { components: [Object] }
},
code: 50035,
status: 400,
method: 'POST',
url: 'https://discord.com/api/v10/channels/1302354912235229307/messages'
}
Uncaught exception: DiscordAPIError[50035]: Invalid Form Body
components[0].components[1].items[0].media.url[UNFURLED_MEDIA_ITEM_REFERENCED_ATTACHMENT_NOT_FOUND]: The referenced attachment ("attachment://votación.png") was not found
at handleErrors (C:\Users\AMD\Desktop\portland\node_modules\@discordjs\rest\dist\index.js:748:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (C:\Users\AMD\Desktop\portland\node_modules\@discordjs\rest\dist\index.js:1149:23)
at async SequentialHandler.queueRequest (C:\Users\AMD\Desktop\portland\node_modules\@discordjs\rest\dist\index.js:980:14)
at async _REST.request (C:\Users\AMD\Desktop\portland\node_modules\@discordjs\rest\dist\index.js:1293:22)
at async TextChannel.send (C:\Users\AMD\Desktop\portland\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:195:15) {
requestBody: {
files: [ [Object] ],
json: {
content: undefined,
tts: false,
nonce: undefined,
enforce_nonce: false,
embeds: undefined,
components: [Array],
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: 32772,
message_reference: undefined,
attachments: [Array],
sticker_ids: undefined,
thread_name: undefined,
applied_tags: undefined,
poll: undefined
}
},
rawError: {
message: 'Invalid Form Body',
code: 50035,
errors: { components: [Object] }
},
code: 50035,
status: 400,
method: 'POST',
url: 'https://discord.com/api/v10/channels/1302354912235229307/messages'
}
Uncaught exception: DiscordAPIError[50035]: Invalid Form Body components[0].components[1].items[0].media.url[UNFURLED_MEDIA_ITEM_REFERENCED_ATTACHMENT_NOT_FOUND]: The referenced attachment ("attachment://votación.png") was not found Whenever I crtl + click the file link it outputs in the terminal, it sends me to the actual file, so I really don't know why this is failing. I've also tried this method in another file, and worked just fine. This is the one that works:
if(message.content === 'devRules') {
if(DEVELOPER_IDS.includes(message.author.id)) {
const rulesMessage = new RulesEmbed(Math.floor(new Date() / 1000), 'attachment://rules.png');
const rulesAttachment = new AttachmentBuilder(path.join(__dirname, '..', 'assets', 'rules.png'), { name: 'rules.png' });

message.channel.send({
components: [ rulesMessage.getEmbed() ],
flags: [
MessageFlags.IsComponentsV2,
MessageFlags.SuppressEmbeds
],
files: [ rulesAttachment ]
});
}
}
if(message.content === 'devRules') {
if(DEVELOPER_IDS.includes(message.author.id)) {
const rulesMessage = new RulesEmbed(Math.floor(new Date() / 1000), 'attachment://rules.png');
const rulesAttachment = new AttachmentBuilder(path.join(__dirname, '..', 'assets', 'rules.png'), { name: 'rules.png' });

message.channel.send({
components: [ rulesMessage.getEmbed() ],
flags: [
MessageFlags.IsComponentsV2,
MessageFlags.SuppressEmbeds
],
files: [ rulesAttachment ]
});
}
}
The rules embed constructor gets as a first arg the actual timestamp to place it at the message, then the second arg is placed in mediagallery's media.url property exactly as it's passed in the constructor.
Gary
GaryOP2d ago
This is the preview of the working one.
No description
Mafia
Mafia2d ago
sorry this comes off as mean but This code is nonsense StartUpEmbed is not a builder ins d.js. also you dont need the MessageFlags.SuppressEmbeds because cv2 disables embed Take a look at the example
Gary
GaryOP2d ago
No, I'm building them as classes for them to be reusable later on. Those classes use d.js builders.
Mafia
Mafia2d ago
ya got it, sorry about that
Gary
GaryOP2d ago
For example
class StartUpEmbed {
constructor() {
}
}

class VotingEmbed extends StartUpEmbed {}
class StartUpEmbed {
constructor() {
}
}

class VotingEmbed extends StartUpEmbed {}
And within, I use the d.js Builders. dw
Mafia
Mafia2d ago
Work to understand your error but the the MessageFlags.SuppressEmbeds thing is still true
Gary
GaryOP2d ago
I get that the code may seem sketchy and bad written, but technically the data that is being posted to discord to send to the channel is valid. Though it does not recognize the attachment. Oh, oke, ty I used it as a precaution, never really had it embed it b4. See how in the terminal it shows the AttachmentBuilder work well but when sent, just randomly breaking.

Did you find this page helpful?