greatalts
greatalts
Explore posts from servers
CDCloudflare Developers
Created by greatalts on 3/12/2024 in #general-help
Uploading Images into Cloudflare using node.js
If anyone struggles with this in the future
3 replies
CDCloudflare Developers
Created by greatalts on 3/12/2024 in #general-help
Uploading Images into Cloudflare using node.js
After 15 hours of research and chatgpt giving me the wrong information. i figured out the function
const axios = require("axios")
const fs = require('fs')
const FormData = require('form-data');

async function uploadImageToCloudFlare(path)
{
const form = new FormData();
form.append('file', fs.readFileSync(path), path);

const API_KEY = process.env.CLOUDFLARE_API_KEY
const ACCOUNT_ID = process.env.CLOUDFLARE_ACCOUNT_ID

const response = await axios.post(
`https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/images/v1`,
form,
{
headers: {
...form.getHeaders(),
'Authorization': `Bearer ${API_KEY}`
}
}
);
return response;
}
const axios = require("axios")
const fs = require('fs')
const FormData = require('form-data');

async function uploadImageToCloudFlare(path)
{
const form = new FormData();
form.append('file', fs.readFileSync(path), path);

const API_KEY = process.env.CLOUDFLARE_API_KEY
const ACCOUNT_ID = process.env.CLOUDFLARE_ACCOUNT_ID

const response = await axios.post(
`https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/images/v1`,
form,
{
headers: {
...form.getHeaders(),
'Authorization': `Bearer ${API_KEY}`
}
}
);
return response;
}
3 replies
DIdiscord.js - Imagine ❄
Created by greatalts on 11/13/2023 in #djs-questions
Setting up try catch for TypeError's
Lemme try
8 replies
DIdiscord.js - Imagine ❄
Created by greatalts on 11/13/2023 in #djs-questions
Setting up try catch for TypeError's
ty
8 replies
DIdiscord.js - Imagine ❄
Created by greatalts on 11/13/2023 in #djs-questions
Setting up try catch for TypeError's
ah oke
8 replies
DIdiscord.js - Imagine ❄
Created by greatalts on 11/13/2023 in #djs-questions
Setting up try catch for TypeError's
Code block
const purchaseEmbed = await PURCHASE_EMBEDS.createPurchaseEmbed({
paymentMethod: paymentMethod
})

const productOptionMenu = await buildProductOptionsMenu();

try{
interaction.update(
{
embeds: [purchaseEmbed],
components: [new ActionRowBuilder().addComponents(
productOptionMenu
)]
}
)
}catch(err){
console.log(err)
console.log("ERERFDSFD")
}
break;
const purchaseEmbed = await PURCHASE_EMBEDS.createPurchaseEmbed({
paymentMethod: paymentMethod
})

const productOptionMenu = await buildProductOptionsMenu();

try{
interaction.update(
{
embeds: [purchaseEmbed],
components: [new ActionRowBuilder().addComponents(
productOptionMenu
)]
}
)
}catch(err){
console.log(err)
console.log("ERERFDSFD")
}
break;
8 replies
DIdiscord.js - Imagine ❄
Created by greatalts on 11/13/2023 in #djs-questions
Setting up try catch for TypeError's
Stack Trace
C:\Users\paulk\Desktop\AltsGreatDiscordBot\node_modules\@discordjs\builders\dist\index.js:1310
components: this.components.map((component) => component.toJSON())
^

TypeError: Cannot read properties of undefined (reading 'toJSON')
at C:\Users\paulk\Desktop\AltsGreatDiscordBot\node_modules\@discordjs\builders\dist\index.js:1310:64
at Array.map (<anonymous>)
at ActionRowBuilder.toJSON (C:\Users\paulk\Desktop\AltsGreatDiscordBot\node_modules\@discordjs\builders\dist\index.js:1310:35)
at C:\Users\paulk\Desktop\AltsGreatDiscordBot\node_modules\discord.js\src\structures\MessagePayload.js:136:109
at Array.map (<anonymous>)
at MessagePayload.resolveBody (C:\Users\paulk\Desktop\AltsGreatDiscordBot\node_modules\discord.js\src\structures\MessagePayload.js:136:49)
at StringSelectMenuInteraction.update (C:\Users\paulk\Desktop\AltsGreatDiscordBot\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:231:56)
at handleMenuSelect (C:\Users\paulk\Desktop\AltsGreatDiscordBot\src\Interactions\MenuSelects\handleMenuSelect.js:81:41)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v20.7.0
C:\Users\paulk\Desktop\AltsGreatDiscordBot\node_modules\@discordjs\builders\dist\index.js:1310
components: this.components.map((component) => component.toJSON())
^

TypeError: Cannot read properties of undefined (reading 'toJSON')
at C:\Users\paulk\Desktop\AltsGreatDiscordBot\node_modules\@discordjs\builders\dist\index.js:1310:64
at Array.map (<anonymous>)
at ActionRowBuilder.toJSON (C:\Users\paulk\Desktop\AltsGreatDiscordBot\node_modules\@discordjs\builders\dist\index.js:1310:35)
at C:\Users\paulk\Desktop\AltsGreatDiscordBot\node_modules\discord.js\src\structures\MessagePayload.js:136:109
at Array.map (<anonymous>)
at MessagePayload.resolveBody (C:\Users\paulk\Desktop\AltsGreatDiscordBot\node_modules\discord.js\src\structures\MessagePayload.js:136:49)
at StringSelectMenuInteraction.update (C:\Users\paulk\Desktop\AltsGreatDiscordBot\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:231:56)
at handleMenuSelect (C:\Users\paulk\Desktop\AltsGreatDiscordBot\src\Interactions\MenuSelects\handleMenuSelect.js:81:41)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v20.7.0
8 replies