Jotos Posted 7 hours ago Posted 7 hours ago (edited) Heya! That's my function: Spoiler Func _GetOrCreateTodayThread($sToken, $sParentChannel) Local $sDate = @YEAR & "-" & StringFormat("%02d", @MON) & "-" & StringFormat("%02d", @MDAY) Local $sThreadName = "Screenshots " & $sDate ; Thread erstellen Local $oC = ObjCreate("WinHttp.WinHttpRequest.5.1") $oC.Open("POST", $API_BASE & "/channels/" & $sParentChannel & "/threads", False) $oC.SetRequestHeader("Authorization", "Bot " & $sToken) $oC.SetRequestHeader("Content-Type", "application/json") $oC.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)") Local $sJson = '{"name":"' & _JsonEscape($sThreadName) & '","auto_archive_duration":1440}' $oC.Send($sJson) ConsoleWrite("HTTP Status: " & $oC.Status & @CRLF) ConsoleWrite("Response: " & $oC.ResponseText & @CRLF) If $oC.Status = 201 Or $oC.Status = 200 Then Local $b = StringRegExp($oC.ResponseText, '"id"\s*:\s*"([0-9]+)"', 3) If IsArray($b) And UBound($b) > 0 Then Return $b[0] Else SetError(1) Return 0 EndIf ElseIf $oC.Status = 429 Then ; Rate-Limit: Retry-After auswerten Local $sRetry = $oC.GetResponseHeader("Retry-After") ConsoleWrite("Rate limited. Retry-After: " & $sRetry & " ms" & @CRLF) Sleep(Ceiling($sRetry)+500) Return _GetOrCreateTodayThread($sToken, $sParentChannel) ; Retry Else SetError(1) Return 0 EndIf EndFunc And here is _JsonEscape: Spoiler Func _JsonEscape($s) $s = StringReplace($s, "\", "\\") $s = StringReplace($s, '"', '\"') $s = StringReplace($s, @CRLF, "\n") $s = StringReplace($s, @CR, "\n") $s = StringReplace($s, @LF, "\n") Return $s EndFunc I want to create a thread on my Discord Server, but I always get this error: Spoiler Quote HTTP Status: 403 Response: {"message": "internal network error", "code": 40333} I try to solve the problem with Google, but only found a solution for Java. It seems, that's the format of $oC is malformed. Edited 7 hours ago by Jotos
argumentum Posted 5 hours ago Posted 5 hours ago 1 hour ago, Jotos said: It seems, that's the format of $oC is malformed. 1 hour ago, Jotos said: Local $oC = ObjCreate("WinHttp.WinHttpRequest.5.1") That is not the answer because $oC is the WinHTTP engine. 1 hour ago, Jotos said: I try to solve the problem with Google, but only found a solution for Java. Java, AutoIt, pizza in a box, ... is all the same. What was the Java solution ? Did the Java solution work for you ? Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Jotos Posted 5 hours ago Author Posted 5 hours ago 5 minutes ago, argumentum said: That is not the answer because $oC is the WinHTTP engine. Java, AutoIt, pizza in a box, ... is all the same. What was the Java solution ? Did the Java solution work for you ? I did it in Python using import discord, but I don’t create the JSON myself — the library handles everything for me 😄
argumentum Posted 5 hours ago Posted 5 hours ago ...play around with that JSON ? Also, your User-Agent has to be "Discord compliant" ( https://discord.com/developers/docs/reference#http-api ) PS: I never coded a Discord bot, nor am good at HTTP stuff. Just looking for obvious stuff like: does the info sent is as per endpoint requirements 🤷♂️ Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Jotos Posted 5 hours ago Author Posted 5 hours ago According to the doku I found this: So.. yhea, will try it. argumentum 1
argumentum Posted 5 hours ago Posted 5 hours ago (edited) yeah, is 40333 Cloudflare access denied (code: 1020). Do post your working code ( minus personal info ) for me to use in the future. Maybe I'll make a popup with "You have mail" ( ala AOL epoch ) Edited 5 hours ago by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now