Uploading larger files fail, when uploading it to my discord bot

when trying to upload, mostly videos, it fails and i get thsi. The problem is, the file never even reaches the discord bot, instantly i see this message. What might be the problem? code: upload.js
const { SlashCommandBuilder } = require('@discordjs/builders');
const fs = require('fs');
const path = require('path');

const whitelistedUsers = [
"614485941423177729",
"1132790424990404659",
"1088653427397107712",
"1259481504065654854"
]

module.exports = {
data: new SlashCommandBuilder()
.setName('upload')
.setDescription('Upload a file')
.addAttachmentOption(option =>
option.setName('file')
.setDescription('The file to upload')
.setRequired(true)),

async execute(interaction) {
if (!whitelistedUsers.includes(interaction.user.id)) {
return interaction.reply({ content: 'You do not have permission to use this command.' });
}
const file = interaction.options.getAttachment('file');
if (!file) {
return interaction.reply({ content: 'No file was provided.', ephemeral: true });
}
const filePath = path.join(__dirname, '../../public/uploads', file.name);
const fileStream = fs.createWriteStream(filePath);
const https = require('https');
https.get(file.url, response => {
response.pipe(fileStream);
fileStream.on('finish', () => {
fileStream.close();
interaction.reply({ content: `File uploaded successfully: http://localhost:3000/uploads/${file.name}`, ephemeral: true });
});
}).on('error', err => {
fs.unlink(filePath, () => {
interaction.reply({ content: 'Failed to upload file.', ephemeral: true });
console.error(err);
});
});
},
};
const { SlashCommandBuilder } = require('@discordjs/builders');
const fs = require('fs');
const path = require('path');

const whitelistedUsers = [
"614485941423177729",
"1132790424990404659",
"1088653427397107712",
"1259481504065654854"
]

module.exports = {
data: new SlashCommandBuilder()
.setName('upload')
.setDescription('Upload a file')
.addAttachmentOption(option =>
option.setName('file')
.setDescription('The file to upload')
.setRequired(true)),

async execute(interaction) {
if (!whitelistedUsers.includes(interaction.user.id)) {
return interaction.reply({ content: 'You do not have permission to use this command.' });
}
const file = interaction.options.getAttachment('file');
if (!file) {
return interaction.reply({ content: 'No file was provided.', ephemeral: true });
}
const filePath = path.join(__dirname, '../../public/uploads', file.name);
const fileStream = fs.createWriteStream(filePath);
const https = require('https');
https.get(file.url, response => {
response.pipe(fileStream);
fileStream.on('finish', () => {
fileStream.close();
interaction.reply({ content: `File uploaded successfully: http://localhost:3000/uploads/${file.name}`, ephemeral: true });
});
}).on('error', err => {
fs.unlink(filePath, () => {
interaction.reply({ content: 'Failed to upload file.', ephemeral: true });
console.error(err);
});
});
},
};
No description
12 Replies
d.js toolkit
d.js toolkit4mo 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!
maxwalks
maxwalksOP4mo ago
npm list discord.js: └── [email protected] node -v: v21.7.1 it does work with small files, such as images or text and videos do work when theyre under 20mb or something around that is it a code issue?
monbrey
monbrey4mo ago
I suggest you deferReply, clearly its simply taking longer than 3 seconds to process the larger files
maxwalks
maxwalksOP4mo ago
oh okay, how do i do this?
d.js docs
d.js docs4mo ago
:guide: Slash Commands: Command response methods - Deferred responses read more
maxwalks
maxwalksOP4mo ago
and where do i put this in my code exactly? because i tried to put it on the first bit, but it didnt work
monbrey
monbrey4mo ago
Didnt work how? You put it before any actions that are expected to take a long time And make sure to await it
maxwalks
maxwalksOP4mo ago
i did, but the code doesnt even run immediately after entering the command not a ms later it says this
maxwalks
maxwalksOP4mo ago
No description
maxwalks
maxwalksOP4mo ago
its not running any code, it just says this when the file is larger
monbrey
monbrey4mo ago
Is it your upload limit thats the issue then?
maxwalks
maxwalksOP4mo ago
maybe
Want results from more Discord servers?
Add your server