function FileToDiscord { param ( [string]$channelId, [array]$local_file, $header ) $boundary = [System.Guid]::NewGuid().ToString(); $LF = "`r`n"; $contentLength = $bodyLines.Length $fileBytesFwl = [System.IO.File]::ReadAllBytes($local_file[0]) $file_enc_fwl = [System.Text.Encoding]::GetEncoding('UTF-8').GetString($fileBytesFwl) $fileBytesDb = [System.IO.File]::ReadAllBytes($local_file[1]) $file_enc_db = [System.Text.Encoding]::GetEncoding('UTF-8').GetString($fileBytesDb) Write-Host $fileBytesFwl # Write-Host $local_file[0].GetType() # [System.IO.File]::ReadAllBytes($local_file[0]) $bodyLines = ( "--$boundary", "Content-Disposition: form-data; name=`"content`"", "Content-Type: text/plain", "", "test", "--$boundary", "Content-Disposition: form-data; name=`"file[0]`"; filename=`"save.fwl`"", "Content-Type: application/octet-stream$LF", $file_enc_fwl, "--$boundary", "Content-Disposition: form-data; name=`"file[1]`"; filename=`"save.db`"", "Content-Type: application/octet-stream$LF", $file_enc_db, "--$boundary--$LF" ) -join $LF $header["Content-Length"] = $contentLength.ToString() try { $message = Invoke-RestMethod -Uri "https://discord.com/api/v9/channels/$channelId/messages" -Headers $header -UserAgent "" -Method POST -ContentType "multipart/form-data; boundary=`"$boundary`"" -Body $bodyLines # Write-Host $message } }