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

Cannot edit an InteractionMessage #1168

Closed
3 tasks done
apsw171118 opened this issue Feb 27, 2024 · 3 comments · Fixed by #1186
Closed
3 tasks done

Cannot edit an InteractionMessage #1168

apsw171118 opened this issue Feb 27, 2024 · 3 comments · Fixed by #1186
Assignees
Labels
p: medium Priority: medium - should be worked on in the near future t: bug Type: bug - something isn't working

Comments

@apsw171118
Copy link

Summary

Cannot edit a message using the function .edit

Reproduction Steps

"Dropping existing records..\nApplying new records..." basically returns this:
Ignoring exception in command <nextcord.application_command.SlashApplicationSubcommand object at 0x0000022FF5DE32F0>:
Traceback (most recent call last):
File "C:\Users\ng_jo\AppData\Local\Programs\Python\Python312\Lib\site-packages\nextcord\application_command.py", line 918, in invoke_callback_with_hooks
await self(interaction, *args, **kwargs)
File "C:\Users\ng_jo\OneDrive\Backup\Desktop\joshuang\coding.GITHUBCLONE\Testing-Bot\cogs\tickets_init_.py", line 319, in register_config
await msg.edit(
File "C:\Users\ng_jo\AppData\Local\Programs\Python\Python312\Lib\site-packages\nextcord\interactions.py", line 1180, in edit
message = await self._state._interaction.edit_original_message(
^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'ConnectionState' object has no attribute '_interaction'

The above exception was the direct cause of the following exception:

nextcord.errors.ApplicationInvokeError: Command raised an exception: AttributeError: 'ConnectionState' object has no attribute '_interaction'

Minimal Reproducible Code

@setup.subcommand(name="register")
    # @application_checks.is_owner()
    async def register_config(
        self,
        interaction,
        guild_id=str,
        category_id=str,
        staff_id=str,
        transcript_id=str,
    ):
        guild = self.bot.get_guild(int(guild_id))
        if self.bot.get_guild(int(guild_id)):
            if guild.get_channel(int(transcript_id)):
                if nextcord.utils.get(guild.categories, id=int(category_id)):
                    if not fetch(
                        "storage/tickets.sqlite",
                        "TicketConfig",
                        f"guild_id={guild_id}",
                    ):
                        insert(
                            "storage/tickets.sqlite",
                            "TicketConfig",
                            ("guild_id", "category_id", "staff_id", "transcript_id"),
                            (guild_id, category_id, staff_id, transcript_id),
                        )
                    else:
                        view = ConfirmView()
                        data = fetch("storage/tickets.sqlite", "TicketConfig")
                        for i in range(len(data)):
                            if data[i][0] == int(guild_id):
                                data = data[i]
                                break
                        msg = await interaction.response.send_message(
                            f"Guild already registered, overwrite?\n### CONFIGURATION FOR THIS GUILD\n- Guild ID: {interaction.guild.name} ({data[0]})\n- Category ID: <#{data[1]}> ({data[1]})\n- Staff ID: <@&{data[2]}> ({data[2]}\n- Transcript Channel: <#{data[3]}> ({data[3]})",
                            view=view,
                        )
                        await view.wait()
                        if view is None:
                            await msg.edit("Action cancelled.")
                        elif view.value:
                            msg = await msg.edit(
                                content="Overwriting the existing record...", view=None
                            )
                            drop(
                                "storage/tickets.sqlite",
                                "TicketConfig",
                                f"guild_id={guild_id}",
                            )
                            await msg.edit(
                                "Dropped existing records..\nApplying new records..."
                            )
                            insert(
                                "storage/tickets.sqlite",
                                "TicketConfig",
                                (
                                    "guild_id",
                                    "category_id",
                                    "staff_id",
                                    "transcript_id",
                                ),
                                (guild_id, category_id, staff_id, transcript_id),
                            )
                            # await msg.edit(
                            #    f"Registered guild.\n{fetch('storage/tickets.sqlite', 'TicketConfig', f'WHERE guild_id={guild_id}')}"
                            # )
                else:
                    await interaction.response.send_message(
                        "Invalid `category_id`. Perhaps the bot doesn't have the permission to view it?"
                    )
            else:
                await interaction.response.send_message(
                    "Invalid `transcript_id`. Maybe the bot doesn't have access to all the channels?"
                )
        else:
            await interaction.response.send_message(
                "Invalid `guild_id`, maybe the bot is not in the guild?"
            )

Expected Results

edit the message

Actual Results

threw me an error idk what it means

Intents

nextcord.Intents.all()

System Information

nextcord-ext-menus 1.5.7

  • Python v3.12.1-final
  • nextcord v2.6.0-final
  • aiohttp v3.9.1
  • system info: Windows 10 10.0.19045
    i've got discord.py i don't think it would affect it tho...

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

support thread here: https://ptb.discord.com/channels/881118111967883295/1212126972784807987

@apsw171118 apsw171118 added the t: unconfirmed bug Type: bug - needs testing on if this is an issue label Feb 27, 2024
@ooliver1
Copy link
Member

Can you make the minimal reproducible code actually minimal? It's hard to understand with multiple nested conditions.

@apsw171118
Copy link
Author

apsw171118 commented Mar 1, 2024

@nextcord.slash_command(name="bug-test")
async def bugtest(self, interaction):
    msg = await interaction.response.send_message("abc1")
    msg = await msg.edit("abc2")
    msg = await msg.edit("abc3")

At third edit:
image

Ignoring exception in command <nextcord.application_command.SlashApplicationCommand object at 0x00000244D4B5D3D0>:
Traceback (most recent call last):
  File "C:\Users\ng_jo\AppData\Local\Programs\Python\Python312\Lib\site-packages\nextcord\application_command.py", line 918, in invoke_callback_with_hooks
    await self(interaction, *args, **kwargs)
  File "C:\Users\ng_jo\OneDrive\Backup\Desktop\joshuang\coding\.GITHUBCLONE\Testing-Bot\cogs\dev\__init__.py", line 123, in bugtest
    msg = await msg.edit("abc3")
          ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ng_jo\AppData\Local\Programs\Python\Python312\Lib\site-packages\nextcord\interactions.py", line 1180, in edit
    message = await self._state._interaction.edit_original_message(
                    ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'ConnectionState' object has no attribute '_interaction'

The above exception was the direct cause of the following exception:

nextcord.errors.ApplicationInvokeError: Command raised an exception: AttributeError: 'ConnectionState' object has no attribute '_interaction' 

image

sorry for the multiple edits, still getting used to the github markdown 😅

@teaishealthy
Copy link
Collaborator

Can reproduce.

As a temporary fix you can not collect the message until the end:

@nextcord.slash_command(name="bug-test")
async def bugtest(self, interaction):
    msg = await interaction.response.send_message("abc1")
    await msg.edit("abc2")
    msg = await msg.edit("abc3")
	print(msg.content)  # abc3

@teaishealthy teaishealthy added t: bug Type: bug - something isn't working p: medium Priority: medium - should be worked on in the near future and removed t: unconfirmed bug Type: bug - needs testing on if this is an issue labels Apr 19, 2024
@teaishealthy teaishealthy self-assigned this Apr 19, 2024
teaishealthy added a commit to teaishealthy/disnake that referenced this issue Apr 19, 2024
@teaishealthy teaishealthy added the s: awaiting review Status: the issue or PR is awaiting reviews label Apr 19, 2024
@EmreTech EmreTech removed the s: awaiting review Status: the issue or PR is awaiting reviews label May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p: medium Priority: medium - should be worked on in the near future t: bug Type: bug - something isn't working
Projects
None yet
4 participants