C
C#5w ago
n1ls

Post file to Discord channel

hey guys, has any of you tried to use the Discord api to send Valheim saves game to a Discord channel (to share them with friends, etc.)? My script (https://srcb.in/T7lfthUtfP) sends these files to the channel but after downloading, Valheim can't make use of them. I am sending them according to Discords specs https://discord.com/developers/docs/reference#uploading-files but I reckon that my encoding before sending might be the problem, but I am stuck here, as my understanding of http/encoding is limited Cheers!
Discord Developer Portal
Discord Developer Portal — API Docs for Bots and Developers
Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.
14 Replies
Angius
Angius5w ago
O-oh, that's Powershell Might get more help on the $powershell server
Angius
Angius5w ago
I don't think I would be reading those binary files as a UTF-8 string That's for sure
n1ls
n1ls5w ago
that is where I am stuck^^ How else would you do it 🙂
Angius
Angius5w ago
I would not use Powershell lol But if I had to, I'd try googling, and I might even find something like this: https://stackoverflow.com/questions/22491129/how-to-send-multipart-form-data-with-powershell-invoke-restmethod Which basically uses .NET's HttpClient
n1ls
n1ls5w ago
yeah, I already read that^^ But might give it another try well, I am a little surprised: using HttpClient works, so I can load the save games now ...does this automatically mean the sent files are safely not corrupted? Like, in my mind I figure that I still might get an error at some point like "cant find asset..."
Angius
Angius5w ago
You're sending the exact bytes that are on your disk So the files should be a 1:1 copy
n1ls
n1ls5w ago
because I am sending a file stream now?
Angius
Angius5w ago
Yeah Without serializing it as text
n1ls
n1ls5w ago
so it should also work with my previous approach, when I use $fileStream = [System.IO.File]::OpenRead($local_file[1]) instead of $fileBytesFwl = [System.IO.File]::ReadAllBytes($local_file[0]) thanks anyway^^
Unknown User
Unknown User5w ago
Message Not Public
Sign In & Join Server To View
n1ls
n1ls5w ago
Yeah I use a bot token...the script sends the request upon which the bot account posts the message. Is this design not common? Thanks for pointing this out. A lot of this needs cleaning I see, the project was really just a quick idea and without knowing too much about discord bots I just followed this way. What would be a more professional design? I just want to run a script now and then to send a few save files to a Channel and or download a few.
Unknown User
Unknown User5w ago
Message Not Public
Sign In & Join Server To View
n1ls
n1ls5w ago
So the setting is the following: we share the save files in our channel. So every user needs to check which version is newer, local or remote and manually upload or download the most recent accordingly. Now I want a script which every user can run which checks which version is newer and uploads or downloads the files. I have it all complete already, just the upload was problematic as the files couldn't be read, but using http client fixed it. It could use a totally different design if mine is total crap though