pycord: AttributeError: 'NoneType' object has no attribute 'get_thread'
Summary
When upgrading from 2.0.0-rc.1 to 2.0.0, I’m getting this error.
Reproduction Steps
My code calls channel.history() and iterates over messages in the channel. This is the trailing end of the stack trace I get:
async for message in channel.history(limit=None, after=history_after):
File "/home/circleci/.cache/pypoetry/virtualenvs/juniorguru-3aSsmiER-py3.8/lib/python3.8/site-packages/discord/iterators.py", line 125, in __anext__
return await self.next()
File "/home/circleci/.cache/pypoetry/virtualenvs/juniorguru-3aSsmiER-py3.8/lib/python3.8/site-packages/discord/iterators.py", line 325, in next
await self.fill_messages()
File "/home/circleci/.cache/pypoetry/virtualenvs/juniorguru-3aSsmiER-py3.8/lib/python3.8/site-packages/discord/iterators.py", line 359, in fill_messages
await self.messages.put(self.state.create_message(channel=channel, data=element))
File "/home/circleci/.cache/pypoetry/virtualenvs/juniorguru-3aSsmiER-py3.8/lib/python3.8/site-packages/discord/state.py", line 1693, in create_message
return Message(state=self, channel=channel, data=data)
File "/home/circleci/.cache/pypoetry/virtualenvs/juniorguru-3aSsmiER-py3.8/lib/python3.8/site-packages/discord/message.py", line 764, in __init__
ref.resolved = self.__class__(channel=chan, data=resolved, state=state) # type: ignore
File "/home/circleci/.cache/pypoetry/virtualenvs/juniorguru-3aSsmiER-py3.8/lib/python3.8/site-packages/discord/message.py", line 776, in __init__
self.thread = Thread(guild=self.guild, state=self._state, data=data["thread"])
File "/home/circleci/.cache/pypoetry/virtualenvs/juniorguru-3aSsmiER-py3.8/lib/python3.8/site-packages/discord/threads.py", line 160, in __init__
self._from_data(data)
File "/home/circleci/.cache/pypoetry/virtualenvs/juniorguru-3aSsmiER-py3.8/lib/python3.8/site-packages/discord/threads.py", line 190, in _from_data
if thread := self.guild.get_thread(self.id) and data.pop("_invoke_flag", False):
AttributeError: 'NoneType' object has no attribute 'get_thread'
Minimal Reproducible Code
No response
Expected Results
Pycord should be able to instantiate and return the Message object.
Actual Results
Pycord crashes as self.guild probably isn’t set.
Intents
guilds, members, message_content
System Information
- Python v3.8.7-final
- py-cord v2.0.0-candidate
- py-cord pkg_resources: v2.0.0rc1
- aiohttp v3.8.1
- system info: Darwin 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:29 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T8101
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
Possibly related to @baronkobama’s https://github.com/Pycord-Development/pycord/pull/1447
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17 (16 by maintainers)
Commits related to this issue
- upgrade py-cord after https://github.com/Pycord-Development/pycord/issues/1491 got fixed — committed to juniorguru/junior.guru by honzajavorek 2 years ago
I’m running into the same problem with my threads
Upgraded to v2.1.1 and it seems to work like a charm 🤩 Thank you so much!
I found how to reproduce. When creating a thread from a message:
The initial message will act as the message reference of the actually sent message. Since the channel (of the original message) is different from the message’s channel (the thread), this code is triggered:
https://github.com/Pycord-Development/pycord/blob/8731e1f15a3671aa882cfd346eaedf0c730a8845/discord/state.py#L479-L489
The
referenced_messagedata in the payload does not include a guild_id, so it returns a DMChannel#1551 should fix it
#1447 isn’t related