From 5fd5504744bfacaa6022e9c30fb9952c9c6e0a09 Mon Sep 17 00:00:00 2001 From: Siwoo Jeon Date: Sat, 5 Apr 2025 16:35:28 +0900 Subject: [PATCH] fix: Add disappeared cancel button interaction --- components/deleteLearnedData.go | 14 +++++++++++++- main.go | 2 +- utils/interactions.go | 8 ++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/components/deleteLearnedData.go b/components/deleteLearnedData.go index 51f2db2..4737d11 100644 --- a/components/deleteLearnedData.go +++ b/components/deleteLearnedData.go @@ -24,6 +24,18 @@ var DeleteLearnedDataComponent *commands.Component = &commands.Component{ } userId = customId[len(utils.DeleteLearnedDataCancel):] + if i.Member.User.ID == userId { + i.Update(&discordgo.InteractionResponseData{ + Embeds: []*discordgo.MessageEmbed{ + { + Title: "❌ 취소", + Description: "지식 삭제 작업ㅇ을 취소했어요.", + Color: utils.EmbedFail, + }, + }, + }) + return false + } } else { if !strings.HasPrefix(customId, utils.DeleteLearnedDataUserId) { return false @@ -39,7 +51,7 @@ var DeleteLearnedDataComponent *commands.Component = &commands.Component{ { Title: "❌ 오류", Description: "당신은 해당 권한이 없ㅇ어요.", - Color: int(utils.EmbedFail), + Color: utils.EmbedFail, }, }, Components: []discordgo.MessageComponent{}, diff --git a/main.go b/main.go index d40f217..1d25d80 100644 --- a/main.go +++ b/main.go @@ -39,7 +39,7 @@ func main() { dg.Open() for _, cmd := range commands.Discommand.Commands { - dg.ApplicationCommandCreate(dg.State.User.ID, "", cmd.ApplicationCommand) + go dg.ApplicationCommandCreate(dg.State.User.ID, "", cmd.ApplicationCommand) } defer func() { diff --git a/utils/interactions.go b/utils/interactions.go index 69c1955..a2245be 100644 --- a/utils/interactions.go +++ b/utils/interactions.go @@ -54,3 +54,11 @@ func (i *InteractionCreate) DeferUpdate() { func (i *InteractionCreate) EditReply(data *discordgo.WebhookEdit) { i.Session.InteractionResponseEdit(i.Interaction, data) } + +// Update to this interaction. +func (i *InteractionCreate) Update(data *discordgo.InteractionResponseData) { + i.Session.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ + Type: discordgo.InteractionResponseUpdateMessage, + Data: data, + }) +}