Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when editing a fetched message from a partial webhook #2298

Closed
3 tasks done
thegamecracks opened this issue Dec 23, 2023 · 0 comments · Fixed by #2343
Closed
3 tasks done

TypeError when editing a fetched message from a partial webhook #2298

thegamecracks opened this issue Dec 23, 2023 · 0 comments · Fixed by #2343
Labels
unconfirmed bug A bug report that needs triaging

Comments

@thegamecracks
Copy link
Contributor

thegamecracks commented Dec 23, 2023

Summary

When editing a message that was fetched by a partial webhook, it fails with a TypeError.

Reproduction Steps

  1. Create a partial webhook
  2. Send a message and store the resulting WebhookMessage object
  3. Re-fetch the message using fetch_message()
  4. Attempt to edit the message

Minimal Reproducible Code

import asyncio
import aiohttp
import discord

async def main():
    async with aiohttp.ClientSession() as session:
        webhook = discord.Webhook.partial(1234, "token", session=session)
        message = await webhook.send("Hello world!", wait=True)
        message = await webhook.fetch_message(message.id)
        await message.edit(content="A whole new world!")

asyncio.run(main())

Expected Results

The message should have been edited.

Actual Results

The message is not edited, and the following error is raised:

Traceback (most recent call last):
  File "main.py", line 16, in <module>
    asyncio.run(main())
  File "..\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "..\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "main.py", line 14, in main
    await message.edit(content="A whole new world!")
  File "..\.venv\Lib\site-packages\discord\webhook\async_.py", line 892, in edit
    thread = Object(self._thread_id)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "..\.venv\Lib\site-packages\discord\object.py", line 77, in __init__
    id = int(id)
         ^^^^^^^
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

Intents

N/A

System Information

..\.venv\Lib\site-packages\discord\__main__.py:33: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  import pkg_resources
- Python v3.11.7-final
- py-cord v2.4.1-final
- aiohttp v3.8.6
- system info: Windows 10 10.0.22631

(note: actual operating system is Windows 11)

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

Looking through the source code, it appears that this bug was introduced by d56dc86, where WebhookMessage._thread_id can be assigned None in fetch_message() while WebhookMessage.edit() assumes that the attribute can never be None.

msg = self._create_message(data)
if isinstance(msg.channel, PartialMessageable):
msg._thread_id = thread_id

if hasattr(self, "_thread_id"):
thread = Object(self._thread_id)

@thegamecracks thegamecracks added the unconfirmed bug A bug report that needs triaging label Dec 23, 2023
@Dorukyum Dorukyum linked a pull request Jan 24, 2024 that will close this issue
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unconfirmed bug A bug report that needs triaging
Projects
None yet
1 participant