Skip to content

webhook.edit_message does not work with Views #3238

@InvalidDavid

Description

@InvalidDavid

Summary

cant edit a normal cv2 msg

Reproduction Steps

  1. send cv2 msg
  2. edit it

Minimal Reproducible Code

from utils.imports import *
import aiohttp

WEBHOOK_URL = ".."


class Test(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @slash_command()
    async def test(self, ctx: discord.ApplicationContext):

        await ctx.respond("...", ephemeral=True)

        session = aiohttp.ClientSession()

        webhook = discord.Webhook.from_url(
            WEBHOOK_URL,
            session=session
        )

        await webhook.send(
            content="",
            wait=True,
            view=discord.ui.DesignerView(
                discord.ui.Container(
                    discord.ui.TextDisplay("test"),
                    color=discord.Color.embed_background()
                )
            )
        )

        await session.close()

    @slash_command()
    async def edit(self, ctx: discord.ApplicationContext):

        await ctx.respond("...", ephemeral=True)

        session = aiohttp.ClientSession()

        webhook = discord.Webhook.from_url(
            WEBHOOK_URL,
            session=session
        )

        last_message = None

        async for msg in ctx.channel.history(limit=20):
            if msg.webhook_id is not None:
                last_message = msg
                break

        if last_message is None:
            await session.close()
            return await ctx.followup.send(".", ephemeral=True)

        new_view = discord.ui.DesignerView(
            discord.ui.Container(
                discord.ui.TextDisplay(content="idk"),
                color=discord.Color.gold(),
            )
        )

        await webhook.edit_message(
            message_id=last_message.id,
            content="",
            view=new_view
        )

        return await session.close()


def setup(bot):
    bot.add_cog(Test(bot))

Expected Results

edit the msg

Actual Results

Traceback (most recent call last):
  File "C:\Users\inval\PycharmProjects\Y - K\.venv\Lib\site-packages\discord\commands\core.py", line 136, in wrapped
    ret = await coro(arg)
          ^^^^^^^^^^^^^^^
  File "C:\Users\inval\PycharmProjects\Y - K\.venv\Lib\site-packages\discord\commands\core.py", line 1107, in _invoke
    await self.callback(self.cog, ctx, **kwargs)
  File "C:\Users\inval\PycharmProjects\Y - K\cog\test.py", line 70, in edit
    await webhook.edit_message(
    ...<3 lines>...
    )
  File "C:\Users\inval\PycharmProjects\Y - K\.venv\Lib\site-packages\discord\webhook\async_.py", line 2119, in edit_message
    self._state.prevent_view_updates_for(message_id)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\inval\PycharmProjects\Y - K\.venv\Lib\site-packages\discord\webhook\async_.py", line 876, in __getattr__
    raise AttributeError(f"PartialWebhookState does not support {attr!r}.")
AttributeError: PartialWebhookState does not support 'prevent_view_updates_for'.```

Intents

all

System Information

- Python v3.13.0-final
- py-cord v2.8.None-final
- aiohttp v3.13.3
- system info: Windows 11 10.0.26200

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

No one assigned

    Labels

    bugSomething isn't working

    Type

    No fields configured for Bug.

    Projects

    Status
    In Progress

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions