Maverick
Maverick
DIAdiscord.js - Imagine an app
Created by Maverick on 3/24/2025 in #djs-questions
Get attachment from command after modal submit
Hi there :waveBoye: I'm currently working on a small /bug report command for a friend of mine. For now, it works like this: - 1 Call the command and attach an Image (via .addAttachmentOption) - 2 Hit enter. Modal shows up > More info to add! Submit and done. So, here's my question: What is the easiest way of getting an attachment url for an embed that'll be send to a private channel? -# I thought I could make it easy for myself, but unfortunately I can't haha. Obviously, no more command data is transferred with a modal submit... :nerdSplain_siera: Here'y my small test code:
import { getChannel } from "./xyz";
import { EmbedBuilder } from 'discord.js';

export const data = { customIdPrefix: 'bugReport' };

export async function execute(interaction) {
// Get all the input values from the modal - test for now...
const module = interaction.fields.getTextInputValue('bugReport1') || '/';
const bugDescription = interaction.fields.getTextInputValue('bugReport2') || '/';
const reproductionSteps = interaction.fields.getTextInputValue('bugReport3') || '/';
const optionalLinks = interaction.fields.getTextInputValue('bugReport4') || '/';

// Error: Cannot read property 'getAttachment' of undefined
const optionalScreenshot = interaction.options.getAttachment('screenshot');

const guild = interaction.guild;
const forumChannelId = '1353799943244222465'; // Static ID for now...
const forumChannel = await getChannel(guild, forumChannelId);

const postTitle = `${interaction.user.username}: ${module}`.slice(0, 100); // Limit to 100 characters
const postContent = `🦺`;

const post = await forumChannel.threads.create({
name: postTitle,
autoArchiveDuration: 1440, // 1440 Minutes = 24 hours
reason: 'New bug report',
message: {
content: postContent,
}
});

const postEmbed = new EmbedBuilder()
.setTitle('Bug Report Details')
.addFields(
{ name: 'Module', value: module },
{ name: 'Description', value: bugDescription },
{ name: 'Reproduction Steps', value: reproductionSteps },
{ name: 'Optional Links', value: optionalLinks }
)
.setImage(optionalScreenshot?.url)
.setFooter({
iconURL: interaction.user.displayAvatarURL(),
text: `Reported by ${interaction.user.username}`
})
.setTimestamp()
.setColor('DarkGrey');

await post.send({ embeds: [postEmbed] });

const successEmbed = new EmbedBuilder()
.setDescription('test 123')
.setColor('Green');
await interaction.reply({ embeds: [successEmbed], ephemeral: true });
}
import { getChannel } from "./xyz";
import { EmbedBuilder } from 'discord.js';

export const data = { customIdPrefix: 'bugReport' };

export async function execute(interaction) {
// Get all the input values from the modal - test for now...
const module = interaction.fields.getTextInputValue('bugReport1') || '/';
const bugDescription = interaction.fields.getTextInputValue('bugReport2') || '/';
const reproductionSteps = interaction.fields.getTextInputValue('bugReport3') || '/';
const optionalLinks = interaction.fields.getTextInputValue('bugReport4') || '/';

// Error: Cannot read property 'getAttachment' of undefined
const optionalScreenshot = interaction.options.getAttachment('screenshot');

const guild = interaction.guild;
const forumChannelId = '1353799943244222465'; // Static ID for now...
const forumChannel = await getChannel(guild, forumChannelId);

const postTitle = `${interaction.user.username}: ${module}`.slice(0, 100); // Limit to 100 characters
const postContent = `🦺`;

const post = await forumChannel.threads.create({
name: postTitle,
autoArchiveDuration: 1440, // 1440 Minutes = 24 hours
reason: 'New bug report',
message: {
content: postContent,
}
});

const postEmbed = new EmbedBuilder()
.setTitle('Bug Report Details')
.addFields(
{ name: 'Module', value: module },
{ name: 'Description', value: bugDescription },
{ name: 'Reproduction Steps', value: reproductionSteps },
{ name: 'Optional Links', value: optionalLinks }
)
.setImage(optionalScreenshot?.url)
.setFooter({
iconURL: interaction.user.displayAvatarURL(),
text: `Reported by ${interaction.user.username}`
})
.setTimestamp()
.setColor('DarkGrey');

await post.send({ embeds: [postEmbed] });

const successEmbed = new EmbedBuilder()
.setDescription('test 123')
.setColor('Green');
await interaction.reply({ embeds: [successEmbed], ephemeral: true });
}
4 replies