Skip to content

get_or_fetch allows discord.Thread but doesn't handle it. #3100

@akosjdlk-60

Description

@akosjdlk-60

Summary

title

Reproduction Steps

See MRC.

Minimal Reproducible Code

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"])

Expected Results

.

Actual Results

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

Intents

.

System Information

- Python v3.13.7-final
- py-cord v2.7.None-final
- aiohttp v3.12.15
- system info: Linux 5.15.0-168-generic 178-Ubuntu SMP Fri Jan 9 19:05:03 UTC 2026

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

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions