im currenty creating a discord bot in python using pycord. I have a command that send a message with an embed with two fields. One named Yes and has the value 0 and the other named No also with the value 0. In the select menu I created two options. Option Yes and Option No. My goal is to increase the value of the fields of the embed without resending the select menu, so the selection of it stays in there. My Problem is that I am creating a new Embed with the new value, but when sending the view resets itself.
我目前正在使用pycord创建一个Python语言的不和谐机器人。我有一个发送消息的命令,其中嵌入了两个字段。一个名为Yes,值为0;另一个名为No,值也为0。在选择菜单中,我创建了两个选项。选项是和选项否。我的目标是在不重新发送选择菜单的情况下增加嵌入的字段的值,这样它的选择就会保留在那里。我的问题是,我正在创建一个具有新值的新嵌入,但在发送时视图会自动重置。
This is my select menu callback function:
这是我的选择菜单回调函数:
async def select_callback(self, select, interaction):
embed = interaction.message.embeds[0]
fields = embed.fields
new_embed = discord.Embed(
title=embed.title,
description=embed.description,
)
for field in fields:
if field.name == "Yes" and select.values[0] == "Yes":
new_embed.add_field(name="Yes", value=str(int(field.value) + 1), inline=True)
await interaction.response.send_message("You voted for `Yes`", ephemeral=True)
elif field.name == "No" and select.values[0] == "No":
new_embed.add_field(name="No", value=str(int(field.value) + 1), inline=True)
await interaction.response.send_message("ou voted for `No`", ephemeral=True)
else:
new_embed.add_field(name=field.name, value=field.value, inline=field.inline)
await interaction.message.edit(embed=new_embed)
I've asked ChatGPT for some solutions, but none of them worked. I also googled and didn't find a solution. I also tried myself and I tried splitting the view and the embed in two messages. Unfortunately without any solution.
我已经向ChatGPT寻求了一些解决方案,但都没有奏效。我也在谷歌上搜索,也没有找到解决方案。我也试过了,我试着在两条消息中拆分视图和嵌入。不幸的是,没有任何解决方案。
更多回答
优秀答案推荐
I found out that this isn't possible because the select menu reset itself.
我发现这是不可能的,因为选择菜单会自动重置。
you can set default-values in your options-list by changing the 'default' parameter on your entries:
通过更改条目上的‘Default’参数,您可以在Options-List中设置默认值:
async def select_callback(self, select, interaction):
select.options[0].default = True
await interaction.response.edit_message(view=self)
更多回答
我是一名优秀的程序员,十分优秀!