Description
Summary
Trying to pass file
or files
into ForumChannel.create_thread
raises a HTTPException
due to using the wrong method.
Reproduction Steps
- Attempt to create a forum thread with either the
file
orfiles
parameter
Minimal Reproducible Code
forum_channel_id = ... # Whatever your ID is
path = "..." # some image path
forum_channel = bot.get_channel(forum_channel_id)
await forum_channel.create_thread(name="A Thread", file=discord.File(path))
Expected Results
The thread is created with the file included.
Actual Results
Traceback (most recent call last):
File "/home/container/.local/lib/python3.10/site-packages/discord/channel.py", line 1278, in create_thread
data = await state.http.send_files(
File "/home/container/.local/lib/python3.10/site-packages/discord/http.py", line 366, in request
raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50008): Cannot send messages in a non-text channel
Intents
all
System Information
- Python v3.10.0-final
- py-cord v2.4.0-final
- aiohttp v3.8.1
- system info: Windows 10 10.0.19045
Checklist
- I have searched the open issues for duplicates.
- I have shown the entire traceback, if possible.
- I have removed my token from display, if visible.
Additional Context
This happens because when file
or files
is passed in, we use the separate http.send_files
method which directs to the forum channel ID, not the thread ID.
if file is not None:
...
try:
data = await state.http.send_files(self.id, files=[file], ... ) # ForumChannel ID
finally:
file.close()
elif files is not None:
...
try:
data = await state.http.send_files(self.id, files=files, ... ) # ForumChannel ID
finally:
for f in files:
f.close()
else:
data = await state.http.start_forum_thread(...) # No files arg
This method is only used in the default Messageable.send
and isn't really made for this purpose as it's a send
method, not for creating threads. The thread creation endpoint supports files directly as part of its message payload, so if I had to guess this was just an oversight that hadn't been considered. I've created this issue for posterity and may look into fixing it myself, but if anyone else wants to go for it then be my guest.