Trying to have my discord bot post an image in a channel, and it keeps giving me this error, and I can't figure out why. Here's the code
async execute(interaction) {
try {
const adminRoleId = process.env.ADMIN_ROLE_ID;
const channelId = process.env.CHANNEL_ID;
const imagePath = path.join(__dirname, '..', 'images', 'animationv2.gif');
console.log('Image path:', imagePath); // Add debug output to check the path
const isAdmin = interaction.member.roles.cache.has(adminRoleId);
if (!isAdmin) {
return await interaction.reply({
content: 'You do not have permission to use this command!',
ephemeral: true
});
}
const imageStream = fs.createReadStream(imagePath);
const attachment = { files: [imageStream] };
const channel = await interaction.client.channels.fetch(channelId);
if (!channel) throw new Error('Channel not found.');
await channel.send({ content: 'Here is the image:', files: [attachment] });
await interaction.reply('Image posted successfully!');
} catch (error) {
console.error('Error posting image:', error);
await interaction.reply('There was an error posting the image.');
}
},