难以使.wait()函数与.stop()在不和谐音按钮上工作



提前感谢任何想要帮助我的人。

所以我创建了一个斜杠命令来创建一个带有两个按钮的提醒,以决定下一步要做什么:对命令的调用有效,嵌入也有效,按钮也有效。但是在点击按钮之后,我希望它们停止await视图。wait()使用"交互:discord.Interaction.stop()"来完成for循环并移动到阅读器的下一行。然而,我不认为"交互:不和谐。交互。stop()">

@bot.tree.command(name='reminder')
async def reminder(interaction:discord.Interaction):
buttonyes=Button(label="YES", style=discord.ButtonStyle.green,custom_id="1")
buttonno=Button(label="NO", style=discord.ButtonStyle.red,custom_id="2")
view=View()
with open("C:/Users/market.csv","r",newline='') as incsv, open(f"C:/Users/market2.csv","w+",newline='') as outcsv:
reader = csv.reader(incsv)
writer = csv.writer(outcsv)
for row in reader:
if row[1]=="no" :
async def buttonyes_callback(interaction:discord.Interaction):
row[1]='yes'
writer.writerow(row)
await interaction.response.edit_message(content=f"Offer is canceled",embed=None,view=None)
interaction:discord.Interaction.stop()
async def buttonno_callback(interaction:discord.Interaction):
await interaction.response.edit_message(content=f"Offer is still running",embed=None,view=None)
interaction:discord.Interaction.stop()
buttonyes.callback=buttonyes_callback
buttonno.callback=buttonno_callback
embed = discord.Embed(title='REMINDER', description=f'Is your {row[2]} over ?', color=65280, timestamp = datetime.datetime.now())
embed.add_field(name='Model', value= row[3], inline=True)
embed.add_field(name='Size', value= row[4], inline=True)
embed.add_field(name='Price', value= row[5]+f"€", inline=True)
view.add_item(buttonyes)
view.add_item(buttonno)
writer.writerow(row)
await interaction.response.send_message(embed=embed,view=view)
await view.wait()
else:
writer.writerow(row)

我没有任何错误,但是代码和循环被"await视图停止。wait()">

Thanks in advance

但是我不认为"interaction: dischord . interaction .stop()"我不知道为什么

这一行在语法上没有多大意义,但我现在会忽略它。Interaction.stop()字面上不存在,所以这条线不会做很多事情。不知道你期望发生什么

Docs for Interaction: https://discordpy.readthedocs.io/en/stable/interactions/api.html?highlight=interaction#discord.Interaction

你不能只是使用随机函数,并希望它们存在。先检查一下文档。你可能想在视图上调用stop()实例。

您应该因此得到一个错误,因此您可能没有正确配置日志记录(或者从未到达此代码)。

日志文档:https://discordpy.readthedocs.io/en/stable/logging.html?highlight=logging

buttonyes.callback = buttonyes_callbackbuttonno.callback = buttonno_callback

这不是按钮的方式。不要为了附加回调而重写属性。只是子类View,添加Buttons(无论是与装饰器或使用Button的子类),并创建它的实例。

最新更新