Jump to content

Recommended Posts

Posted (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 by Jotos
Posted
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.
autoit_scripter_blue_userbar.png

Posted
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 😄

Posted

...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.
autoit_scripter_blue_userbar.png

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...