Redus Russ

Generation

translateFri, 07 Jul 2023

const uploadFile = async (filePath, channelID) => { if(!validToken) throw new Error("Invalid token, check your config.js file."); const url = `https://discord.com/api/v9/channels/${channelID}/attachments`, headers = { 'Authorization': token, }, data = { files: [{ filename: filePath.split("/").pop(), file_size: 1337, id: 16 }] }, uploadData = await axios.post(url, data, { headers }).catch(err => err.response); if(uploadData.status !== 200) throw new Error("Error preparing file, please try again.", uploadData.data); const uploadResp = await axios.put(uploadData.data.attachments[0].upload_url, readFileSync(filePath), { headers: { 'Content-Type': 'audio/mpeg' } }).catch(err => err.response); if(uploadResp.status !== 200) throw new Error("Error uploading file, please try again.", uploadResp.data); return uploadData.data.attachments[0].upload_filename; }

async def uploadFile(filePath,channelID): if not validToken: raise Exception("Invalid token, check your config.js file.") url = "https://discord.com/api/v9/channels/"+channelID+"/attachments" headers = { "Authorization": token, } data = { "files": [ { "filename": filePath.split("/").pop(), "file_size": 1337, "id": 16, }, ] } uploadData = await axios.post(url, data, {"headers": headers}).catch(err => err.response) if uploadData.status != 200: raise Exception("Error preparing file, please try again.", uploadData.data) uploadResp = await axios.put( uploadData.data.attachments[0].upload_url, readFileSync(filePath), {"headers": {"Content-Type": "audio/mpeg"}}, ).catch(err

Questions about programming?Chat with your personal AI assistant