Search code examples
pythondiscordpycord

PYCord How can I get message by view?


https://media.discordapp.net/attachments/977648291770667010/977648292206903336/unknown.png

As you can see in the screen shot, there is an explanation about how to edit content of the message when timeout expires in official PyCord website.

But as you can see in this screenshot: https://media.discordapp.net/attachments/977648291770667010/977648292655677440/unknown.png

PyCharm says there is no field called "message".

It appears the same error when debug it:

https://media.discordapp.net/attachments/977648291770667010/977651067007426670/unknown.png?width=1200&height=123

Here is my code:

    class UIAgreement(View):

    def __init__(self, client: Stragate):
        super().__init__(timeout=10)
        self.client = client

    async def on_timeout(self):

        self.disable_all_items()

        await self.message.edit(content="You took too long! Try again.", view=self)

    @button(label="Accept", style=ButtonStyle.success, emoji="👍")
    async def accept_callback(self, event_button: Button, event_interaction: Interaction):

        cursor = self.client.database.cursor()
        cursor.execute(f"SELECT * FROM profiles WHERE id={event_interaction.user.id} LIMIT 1")

        if not cursor.fetchone():
            cursor = self.client.database.cursor()

            cursor.execute("INSERT INTO profiles (id, full_name, job, country, description, thumbnail, "
                           "gender) VALUES (%s, %s, DEFAULT, DEFAULT, DEFAULT, %s, DEFAULT)",
                           (
                               event_interaction.user.id,
                               event_interaction.user.display_name,
                               "https://media.discordapp.net/attachments/976061052548694036"
                               "/977291014047936552/default.jpg"
                           ))
            self.client.database.commit()

            await event_interaction.user.send(embed=Embed(
                title="Successfully registered!",
                description="Please use the 'start' command again."
            ))```


  [1]: https://i.sstatic.net/ymKyQ.png

Solution

  • I learned "Message" field is a field that I need to set out of scope. That's what they said in their discord server. I guess guide is a little bit outdated.