fix: Add disappeared cancel button interaction

This commit is contained in:
Siwoo Jeon 2025-04-05 16:35:28 +09:00
parent 2ca7ce9465
commit 5fd5504744
Signed by: migan
GPG key ID: 036E9A8C5E8E48DA
3 changed files with 22 additions and 2 deletions

View file

@ -24,6 +24,18 @@ var DeleteLearnedDataComponent *commands.Component = &commands.Component{
} }
userId = customId[len(utils.DeleteLearnedDataCancel):] 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 { } else {
if !strings.HasPrefix(customId, utils.DeleteLearnedDataUserId) { if !strings.HasPrefix(customId, utils.DeleteLearnedDataUserId) {
return false return false
@ -39,7 +51,7 @@ var DeleteLearnedDataComponent *commands.Component = &commands.Component{
{ {
Title: "❌ 오류", Title: "❌ 오류",
Description: "당신은 해당 권한이 없ㅇ어요.", Description: "당신은 해당 권한이 없ㅇ어요.",
Color: int(utils.EmbedFail), Color: utils.EmbedFail,
}, },
}, },
Components: []discordgo.MessageComponent{}, Components: []discordgo.MessageComponent{},

View file

@ -39,7 +39,7 @@ func main() {
dg.Open() dg.Open()
for _, cmd := range commands.Discommand.Commands { 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() { defer func() {

View file

@ -54,3 +54,11 @@ func (i *InteractionCreate) DeferUpdate() {
func (i *InteractionCreate) EditReply(data *discordgo.WebhookEdit) { func (i *InteractionCreate) EditReply(data *discordgo.WebhookEdit) {
i.Session.InteractionResponseEdit(i.Interaction, data) 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,
})
}