我有一个非常基本的脚本,它会弹出一条带有命令按钮的消息?位置

单击此按钮后,机器人会向单击它的用户回复Hi.

如果按钮未与进行交互,则为>大约3分钟后,它开始返回"交互失败".

enter image description here

之后按钮就没用了.我假设在文档中找不到某种内部超时.无论是否使用discord,按钮都会执行相同的操作.py(2.0)或pycord.没有任何东西击中控制台.就好像没有点击按钮一样.

偶尔按钮会再次工作,控制台会出现大量错误:

discord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interaction
Ignoring exception in view <View timeout=180.0 children=1> for item <Button style=<ButtonStyle.success: 3> url=None disabled=False label='click me' emoji=None row=None>:

我假设超时=180是导致此问题的原因,但是否有人知道如何停止此超时以及它发生的原因?我在文档中看不到任何关于discord按钮只能使用3分钟的内容.

import discord

from discord.ext import commands
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
bot = commands.Bot(command_prefix="?", intents=intents)


embed1=discord.Embed(title="Test", description = f"TESTING",color=0xffffff)   
print("bot connected")
 
@ bot.command(name='place')
async def hello(ctx):
    view = discord.ui.View()
    buttonSign = discord.ui.Button(label = "click me", style= discord.ButtonStyle.green)


    async def buttonSign_callback(interaction):
        userName = interaction.user.id
        embedText = f"test test test"
        embed=discord.Embed(title="Test", description = embedText,color=0xffffff)
        await interaction.response.send_message(f"Hi <@{userName}>")

       

    buttonSign.callback = buttonSign_callback
    view.add_item(item=buttonSign)
    await ctx.send(embed = embed1,view = view)

bot.run(TOKEN)

推荐答案

解释

默认情况下,View秒不一致.py 2.0的超时为180秒(3分钟).创建视图时,可以通过传入None作为超时来修复此错误.

密码

@bot.command(name='place')
async def hello(ctx):
    view = discord.ui.View(timeout=None)

参考文献

discord.ui.View.timeout

Python相关问答推荐

tempfile.mkstemp(text=.)参数实际上是什么?

双情节在单个图上切换-pPython

使用decorator 自动继承父类

在后台运行的Python函数

如何处理必须存在于环境中但无法安装的Python项目依赖项?

如何将带有逗号分隔的数字的字符串解析为int Array?

为什么dict(id=1,**{id:2})有时会引发KeyMessage:id而不是TypMessage?

Polars:使用列值引用when / then表达中的其他列

使用scipy. optimate.least_squares()用可变数量的参数匹配两条曲线

通过优化空间在Python中的饼图中添加标签

Select 用a和i标签包裹的复选框?

Django管理面板显示字段最大长度而不是字段名称

更改键盘按钮进入'

在线条上绘制表面

如何使用pytest来查看Python中是否存在class attribution属性?

形状弃用警告与组合多边形和多边形如何解决

用砂箱开发Web统计分析

从Windows Python脚本在WSL上运行Linux应用程序

如何在PySide/Qt QColumbnView中删除列

如何创建引用列表并分配值的Systemrame列