fix: Finding nil data
This commit is contained in:
parent
5fd5504744
commit
9b32aaf581
1 changed files with 21 additions and 16 deletions
|
@ -10,7 +10,6 @@ import (
|
|||
"git.wh64.net/muffin/goMuffin/utils"
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
)
|
||||
|
||||
var DeleteLearnedDataCommand *Command = &Command{
|
||||
|
@ -80,22 +79,10 @@ func deleteLearnedDataRun(c *Command, s *discordgo.Session, m any, args *[]strin
|
|||
if err != nil {
|
||||
embed := &discordgo.MessageEmbed{
|
||||
Title: "❌ 오류",
|
||||
Description: "데이터를 가져오는데 실패했어요.",
|
||||
Color: utils.EmbedFail,
|
||||
}
|
||||
if err == mongo.ErrNoDocuments {
|
||||
embed.Description = "해당 하는 지식ㅇ을 찾을 수 없어요."
|
||||
switch m := m.(type) {
|
||||
case *discordgo.MessageCreate:
|
||||
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
||||
case *utils.InteractionCreate:
|
||||
m.EditReply(&discordgo.WebhookEdit{
|
||||
Embeds: &[]*discordgo.MessageEmbed{embed},
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
embed.Description = "데이터를 가져오는데 실패했어요."
|
||||
switch m := m.(type) {
|
||||
case *discordgo.MessageCreate:
|
||||
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
||||
|
@ -109,6 +96,24 @@ func deleteLearnedDataRun(c *Command, s *discordgo.Session, m any, args *[]strin
|
|||
|
||||
cur.All(context.TODO(), &datas)
|
||||
|
||||
if len(datas) < 1 {
|
||||
embed := &discordgo.MessageEmbed{
|
||||
Title: "❌ 오류",
|
||||
Description: "해당 하는 지식ㅇ을 찾을 수 없어요.",
|
||||
Color: utils.EmbedFail,
|
||||
}
|
||||
|
||||
switch m := m.(type) {
|
||||
case *discordgo.MessageCreate:
|
||||
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
||||
case *utils.InteractionCreate:
|
||||
m.EditReply(&discordgo.WebhookEdit{
|
||||
Embeds: &[]*discordgo.MessageEmbed{embed},
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
for i := range len(datas) {
|
||||
data := datas[i]
|
||||
|
||||
|
|
Loading…
Reference in a new issue