See MRC.
import os
import traceback
import discord
import dotenv
dotenv.load_dotenv()
bot = discord.Bot(intents=discord.Intents.all())
GUILD_ID = 1227329814307016814
THREAD_ID = 1432051664214298664
@bot.event
async def on_ready():
guild = await bot.get_or_fetch(discord.Guild, GUILD_ID)
if guild is None:
return
try:
await guild.get_or_fetch(discord.Thread, THREAD_ID)
except Exception as e:
traceback.print_exception(e)
try:
await bot.get_or_fetch(discord.Thread, THREAD_ID)
except Exception as e:
traceback.print_exception(e)
print(type(await bot.get_or_fetch(discord.TextChannel, THREAD_ID)))
bot.run(os.environ["TOKEN"])
.
Traceback (most recent call last):
File "/home/akos/amox/amox-bot/.venv/lib/python3.13/site-packages/discord/utils.py", line 726, in get_or_fetch
getter, fetcher = _get_getter_fetcher_map()[object_type]
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: <class 'discord.threads.Thread'>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/akos/amox/amox-bot/test/getorfetch.py", line 24, in on_ready
await guild.get_or_fetch(discord.Thread, THREAD_ID)
File "/home/akos/amox/amox-bot/.venv/lib/python3.13/site-packages/discord/guild.py", line 1164, in get_or_fetch
return await utils.get_or_fetch(
^^^^^^^^^^^^^^^^^^^^^^^^^
...<4 lines>...
)
^
File "/home/akos/amox/amox-bot/.venv/lib/python3.13/site-packages/discord/utils.py", line 728, in get_or_fetch
raise InvalidArgument(
f"Class {object_type.__name__} cannot be used with discord.{type(obj).__name__}.get_or_fetch()"
)
discord.errors.InvalidArgument: Class Thread cannot be used with discord.Guild.get_or_fetch()
Traceback (most recent call last):
File "/home/akos/amox/amox-bot/.venv/lib/python3.13/site-packages/discord/utils.py", line 726, in get_or_fetch
getter, fetcher = _get_getter_fetcher_map()[object_type]
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: <class 'discord.threads.Thread'>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/akos/amox/amox-bot/test/getorfetch.py", line 29, in on_ready
await bot.get_or_fetch(discord.Thread, THREAD_ID)
File "/home/akos/amox/amox-bot/.venv/lib/python3.13/site-packages/discord/client.py", line 1240, in get_or_fetch
return await utils.get_or_fetch(
^^^^^^^^^^^^^^^^^^^^^^^^^
...<4 lines>...
)
^
File "/home/akos/amox/amox-bot/.venv/lib/python3.13/site-packages/discord/utils.py", line 728, in get_or_fetch
raise InvalidArgument(
f"Class {object_type.__name__} cannot be used with discord.{type(obj).__name__}.get_or_fetch()"
)
discord.errors.InvalidArgument: Class Thread cannot be used with discord.Bot.get_or_fetch()
<class 'discord.threads.Thread'>
.
Summary
title
Reproduction Steps
See MRC.
Minimal Reproducible Code
Expected Results
.
Actual Results
Intents
.
System Information
Checklist
Additional Context
No response