Tcukawi
Tcukawi
Explore posts from servers
DIdiscord.js - Imagine ❄
Created by Tcukawi on 4/18/2024 in #djs-questions
getting error on attaching attachments
jesus christ, it is undefined
9 replies
DIdiscord.js - Imagine ❄
Created by Tcukawi on 4/18/2024 in #djs-questions
getting error on attaching attachments
file.buffer indeed is defined, because on my multer testcase it uploaded the image
9 replies
DIdiscord.js - Imagine ❄
Created by Tcukawi on 4/18/2024 in #djs-questions
getting error on attaching attachments
Error uploading product: TypeError: Cannot read properties of undefined (reading 'Symbol(Symbol.asyncIterator)') at DataResolver.resolveFile (/Users/farrel/Desktop/Code/project-website-fire_fighter/node_modules/discord.js/src/util/DataResolver.js:117:24) at MessagePayload.resolveFile (/Users/farrel/Desktop/Code/project-website-fire_fighter/node_modules/discord.js/src/structures/MessagePayload.js:260:54) at /Users/farrel/Desktop/Code/project-website-fire_fighter/node_modules/discord.js/src/structures/MessagePayload.js:225:85 at Array.map (<anonymous>) at MessagePayload.resolveFiles (/Users/farrel/Desktop/Code/project-website-fire_fighter/node_modules/discord.js/src/structures/MessagePayload.js:225:56) at TextChannel.send (/Users/farrel/Desktop/Code/project-website-fire_fighter/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:154:50) at cdnUpload (file:///Users/farrel/Desktop/Code/project-website-fire_fighter/dist/controller/api/cdnUpload.js:36:46) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
9 replies
DIdiscord.js - Imagine ❄
Created by Tcukawi on 4/18/2024 in #djs-questions
getting error on attaching attachments
export const cdnUpload: RequestHandler = async (req, res) => {
if (!req.files || (req.files as Express.Multer.File[]).length < 1) return res.status(500).json({ message: "No image set" });
try {
// Extract product data from the request
const { produk, price, stock, description } = req.body;
console.log(produk);
console.log(price);
console.log(stock);
const images = (req.files as Express.Multer.File[]).map((file) => new AttachmentBuilder(file.buffer).setFile(file.buffer).setName(file.filename)); // Convert uploaded files to MessageAttachment instances
const id = await generateUniqueID();

// Get the target guild
console.log(client)
const guild = await client.guilds.fetch(process.env.GUILD!);

// Create a new channel in the target guild
const channel = await guild.channels.create({
name: `product-${produk}-${id}`,
reason: 'New product upload',
});

// Send the images and product details to the new channel
const productMessage = await channel.send({
content: `**Product Name:** ${produk}\n**Price:** ${price}\n**Stock:** ${stock}\n**Description:** ${description}`,
files: images,
});

// Create a new product document
const newProduct = new ProductModel({
id,
nama: produk,
price,
stok: stock,
description,
img: productMessage.attachments.map((attachment:Attachment) => attachment.url),
});

// Save the product to the database
await newProduct.save();

// Respond with success
res.status(200).json({ message: 'Product uploaded successfully!' });
} catch (error) {
console.error('Error uploading product:', error);
res.status(500).json({ message: 'Error uploading product.' });
}
};
export const cdnUpload: RequestHandler = async (req, res) => {
if (!req.files || (req.files as Express.Multer.File[]).length < 1) return res.status(500).json({ message: "No image set" });
try {
// Extract product data from the request
const { produk, price, stock, description } = req.body;
console.log(produk);
console.log(price);
console.log(stock);
const images = (req.files as Express.Multer.File[]).map((file) => new AttachmentBuilder(file.buffer).setFile(file.buffer).setName(file.filename)); // Convert uploaded files to MessageAttachment instances
const id = await generateUniqueID();

// Get the target guild
console.log(client)
const guild = await client.guilds.fetch(process.env.GUILD!);

// Create a new channel in the target guild
const channel = await guild.channels.create({
name: `product-${produk}-${id}`,
reason: 'New product upload',
});

// Send the images and product details to the new channel
const productMessage = await channel.send({
content: `**Product Name:** ${produk}\n**Price:** ${price}\n**Stock:** ${stock}\n**Description:** ${description}`,
files: images,
});

// Create a new product document
const newProduct = new ProductModel({
id,
nama: produk,
price,
stok: stock,
description,
img: productMessage.attachments.map((attachment:Attachment) => attachment.url),
});

// Save the product to the database
await newProduct.save();

// Respond with success
res.status(200).json({ message: 'Product uploaded successfully!' });
} catch (error) {
console.error('Error uploading product:', error);
res.status(500).json({ message: 'Error uploading product.' });
}
};
9 replies
DIdiscord.js - Imagine ❄
Created by Tcukawi on 4/18/2024 in #djs-questions
getting typings error
damn it is lmao alright cheers damn my TS is on 4.9.5
6 replies
DIdiscord.js - Imagine ❄
Created by Tcukawi on 4/18/2024 in #djs-questions
getting typings error
no damn way im too old that my typescript is outdated
6 replies
DIdiscord.js - Imagine ❄
Created by Tcukawi on 4/18/2024 in #djs-questions
getting typings error
{ "compilerOptions": { "outDir": "dist", "rootDir": "src", "esModuleInterop": true, "allowSyntheticDefaultImports": true, "target": "es2020", "module": "es2020", "forceConsistentCasingInFileNames": true, "moduleResolution": "node", "strictNullChecks": true, "skipLibCheck": true, "noImplicitAny": true, "strict": true, }, "include": [ "src" ], "exclude": [ "./node_modules", "./node_modules/*", "./node_modules/@types/node/index.d.ts", "node_modules","types","dist" ] }
6 replies