繁体   English   中英

PYCord 如何通过视图获取消息?

[英]PYCord How can I get message by view?

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

正如您在屏幕截图中看到的,PyCord 官方网站上有关于如何在超时到期时编辑消息内容的说明。

但正如您在此屏幕截图中看到的那样: https ://media.discordapp.net/attachments/977648291770667010/977648292655677440/unknown.png

PyCharm 说没有称为“消息”的字段。

调试时出现同样的错误:

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

这是我的代码:

    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.stack.imgur.com/ymKyQ.png

我了解到“消息”字段是我需要设置超出范围的字段。 这就是他们在不和谐服务器中所说的。 我猜指南有点过时了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM