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
On 10/5/2025 at 2:38 PM, argumentum said:

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 :D )

Spoiler
import discord
from discord.ext import commands
from datetime import datetime
import pyautogui
import os
import sys
import argparse

parser = argparse.ArgumentParser(description="Discord Bot mit optionaler Nachricht und Screenshot")
parser.add_argument("-m", "--message", type=str, default=None, help="Nachricht, die gesendet werden soll")
parser.add_argument("-s", "--screenshot", type=int, choices=[0,1], default=0, help="1=Screenshot erstellen, 0=keinen Screenshot")
args = parser.parse_args()

message_to_send = args.message
screenshot_flag = args.screenshot == 1

print(f"Nachricht: {message_to_send}")
print(f"Screenshot: {screenshot_flag}")


# Hier dein Bot-Token einfügen
TOKEN = "<TOKEN>"
GUILD_ID = int(<SERVER-ID>)

intents = discord.Intents.default()
intents.message_content = True 
intents.guilds = True
bot = commands.Bot(command_prefix="!", intents=intents)

@bot.event
async def on_ready():
    print(f"Bot ist eingeloggt als {bot.user}")
    
    guild = bot.get_guild(GUILD_ID)  

    if guild:
        today = datetime.now().strftime("%Y-%m-%d")
        channel_name = f"{today}"

        # Prüfen, ob schon ein Kanal mit dem heutigen Datum existiert
        existing_channel = discord.utils.get(guild.channels, name=channel_name)
        if existing_channel:
            print(f"Textkanal für {today} existiert schon: {existing_channel.name}")
            channel = existing_channel
        else:
            channel = await guild.create_text_channel(
                name=channel_name,
                reason="Automatisch erstellter Textkanal"
            )
            print(f"Neuer Textkanal erstellt: {channel.name}")

        # Nachricht senden (nur, wenn vorhanden und nicht leer)
        if message_to_send and message_to_send.strip():
            await channel.send(message_to_send)
        else:
            print("Keine Nachricht erhalten.")

        # Screenshot erstellen
        if screenshot_flag:
            screenshot = pyautogui.screenshot()
            file_path = f"screenshot_{today}.png"
            screenshot.save(file_path)
            print(f"Screenshot erstellt: {file_path}")

            # Screenshot senden
            await channel.send("", file=discord.File(file_path))
            print(f"Screenshot gesendet an Kanal: {channel.name}")

            # Screenshot wieder löschen
            if os.path.exists(file_path):
                os.remove(file_path)
                print(f"Screenshot '{file_path}' wurde nach Upload gelöscht.")
        else:
            print("Kein Screenshot zu machen.")

    await bot.close()

# Bot starten
bot.run(TOKEN)

 

Basically, he creates a daily channel on Discord + send a message to the channel and/or a screenshot if needed.
Message and screenshot are given with --message <text> --screenshot <1/0>

I use it to document daily progress. 

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