Редактирование embed по нажатию кнопки
Пытаюсь повторить функцию, в которой по нажатию кнопки "голос пользователя" добавляется в определённый столбец Embed. (См. скрины 1 и 2)
@bot.slash_command(description="Создание голосования")
async def voting(inter, title: str, description: str, vote_limit: int = 1, mention_family: str = mention_family):
emb = disnake.Embed(title=title, description=description, colour=disnake.Color.purple())
emb.add_field(name="<:checkmark:905943731067305996> Accepted", value="-", inline=True)
emb.add_field(name="<:deletesign:905943741775368272> Declined", value="-", inline=True)
emb.add_field(name="❔ Tentative", value="-", inline=True)
buttons = disnake.ui.View()
buttons.add_item(disnake.ui.Button(style=disnake.ButtonStyle.secondary, custom_id="checkmark", emoji="<:checkmark:905943731067305996>"))
buttons.add_item(disnake.ui.Button(style=disnake.ButtonStyle.secondary, custom_id="deletesign", emoji="<:deletesign:905943741775368272>"))
buttons.add_item(disnake.ui.Button(style=disnake.ButtonStyle.secondary, custom_id="undecided", emoji="❔"))
content = "<@&904071673429495830>" if mention_family == "Тегнуть" else None
await inter.send(content=content, embed=emb, allowed_mentions=disnake.AllowedMentions(roles=True), view=buttons)
@bot.event
async def on_button_click(inter: disnake.MessageInteraction):
global good, bad, question
user = inter.author.nick.split()[0] if inter.author.nick is not None else inter.author.name
if inter.component.custom_id == "checkmark":
good.append(user)
emb.set_field_at(index=0, name="<:checkmark:905943731067305996> Accepted", value="\n".join(good))
elif inter.component.custom_id == "deletesign":
bad.append(user)
emb.set_field_at(index=1, name="<:deletesign:905943741775368272> Declined", value="\n".join(bad))
elif inter.component.custom_id == "undecided":
question.append(user)
emb.set_field_at(index=2, name="❔ Tentative", value="\n".join(question))
В on_button_click пытаюсь изменить определённый field, но не могу это сделать т.к. emb локальная переменная. Т.е. мне остаётся написать код для изменения значения, всё остальное сделано
Ответы (1 шт):
Автор решения: Felace
→ Ссылка
Первым делом вам надо получить сообщение по его ID
msg = await ctx.fetch_message(msgID)
Дальше просто редактируете сообщение с помощью метода edit
await msg.edit(embed=embed2)

