discord.py按钮超时

发布于 2025-02-06 06:38:20 字数 456 浏览 2 评论 0原文

我是UI接口(按钮)的新手。以下代码是我的Discord机器人的一部分

        button1 = Button(style=discord.ButtonStyle.blurple, emoji='⬅')
        button2 = Button(style=discord.ButtonStyle.blurple, emoji='➡')

        view = View()
        view.add_item(button1)
        view.add_item(button2)

        *some embed code*
        
        message = await ctx.send(embed=embedVar, view=view)

,我想在我的两个按钮上添加超时,并在某个时候禁用它们,但是我正在努力,因为文档上没有示例(不使用子类)。我该怎么办?

I'm new to the ui interface (buttons). This following code is a part of my discord bot

        button1 = Button(style=discord.ButtonStyle.blurple, emoji='⬅')
        button2 = Button(style=discord.ButtonStyle.blurple, emoji='➡')

        view = View()
        view.add_item(button1)
        view.add_item(button2)

        *some embed code*
        
        message = await ctx.send(embed=embedVar, view=view)

Here I want to add a timeout to both of my buttons and disable them after sometime, but I'm struggling a bit as there is no example on the docs (without using subclasses). How can I do so?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

短叹 2025-02-13 06:38:20

它替换您的

view = View()

view = View(timeout=10) #in seconds

内容在该视图中为所有组件添加了超时。

参考: https:// discordpy.readthedocs.io/en/latest/interactions/api.html?highlight = view#discord.ui.ui.view.timeout

Replace your

view = View()

with

view = View(timeout=10) #in seconds

It adds a timeout to all components in that View.

Reference: https://discordpy.readthedocs.io/en/latest/interactions/api.html?highlight=view#discord.ui.View.timeout

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文