kleincordBot/delete.go

49 lines
1.3 KiB
Go
Raw Normal View History

2024-05-03 18:07:31 +02:00
package main
import (
"github.com/bwmarrin/discordgo"
"strconv"
)
func deleteMessages(data discordgo.ApplicationCommandInteractionData, s *discordgo.Session, i *discordgo.InteractionCreate) {
amount, _ := strconv.Atoi(data.Options[0].Value.(string))
if amount > 100 {
amount = 100
}
messages, err := s.ChannelMessages(i.ChannelID, amount, "", "", "")
if err != nil {
return
}
err = s.InteractionRespond(
i.Interaction,
&discordgo.InteractionResponse{
2024-05-03 21:00:32 +02:00
Type: discordgo.InteractionResponseDeferredChannelMessageWithSource,
2024-05-03 18:07:31 +02:00
Data: &discordgo.InteractionResponseData{
Content: "deleting " + strconv.Itoa(len(messages)) + " messages",
},
},
)
if err != nil {
// Handle the error
}
for _, message := range messages {
var Webhooks []*discordgo.Webhook
Webhooks, err = s.ChannelWebhooks(i.ChannelID)
2024-05-03 21:08:48 +02:00
OnlyWebhook, _ := strconv.ParseBool(data.Options[1].Value.(string))
if OnlyWebhook {
for _, Webhook := range Webhooks {
if message.Author.ID == Webhook.ID {
s.ChannelMessageDelete(i.ChannelID, message.ID)
println(message.Content + " deleted")
}
2024-05-03 18:07:31 +02:00
}
2024-05-03 21:08:48 +02:00
} else {
s.ChannelMessageDelete(i.ChannelID, message.ID)
println(message.Content + " deleted")
2024-05-03 18:07:31 +02:00
}
}
2024-05-03 21:00:32 +02:00
s.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{
Content: strconv.Itoa(len(messages)) + " Message deleted",
})
2024-05-03 18:07:31 +02:00
}