Better command abstraction

This commit is contained in:
2024-10-22 17:07:53 -06:00
parent 0130ec538c
commit 13bf11abce
5 changed files with 65 additions and 77 deletions

View File

@ -1,31 +1,12 @@
package command
import (
"fmt"
"himbot/lib"
"time"
"github.com/bwmarrin/discordgo"
)
func PingCommand(s *discordgo.Session, i *discordgo.InteractionCreate) {
if !lib.CheckAndApplyCooldown(s, i, "ping", 5*time.Second) {
return
}
func PingCommand(s *discordgo.Session, i *discordgo.InteractionCreate) (string, error) {
// Customize the response based on whether it's a guild or DM
responseContent := "Pong!"
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: responseContent,
},
})
if err != nil {
fmt.Println("Error responding to interaction:", err)
// Optionally, you could try to send an error message to the user
lib.RespondWithError(s, i, "An error occurred while processing the command")
}
return responseContent, nil
}