feat: Adding deleteAllCommands

This commit is contained in:
Siwoo Jeon 2025-04-12 21:23:20 +09:00
parent e7b653eaa7
commit 5ad31ab926
Signed by: migan
GPG key ID: 036E9A8C5E8E48DA
2 changed files with 54 additions and 0 deletions

View file

@ -0,0 +1,54 @@
package main
import (
"flag"
"fmt"
"io"
"net/http"
"os"
"strings"
"github.com/bwmarrin/discordgo"
"github.com/joho/godotenv"
)
func main() {
godotenv.Load()
var answer string
id := flag.String("id", "", "discordBot's token")
flag.Parse()
fmt.Printf("Do you want to delete all commands? [y/N]: ")
fmt.Scanf("%s", &answer)
if strings.ToLower(answer) != "y" {
os.Exit(1)
}
if os.Getenv("BOT_TOKEN") == "" {
panic(fmt.Errorf("You need a BOT_TOKEN environment."))
}
if *id == "" {
panic(fmt.Errorf("You need a --id flag value."))
}
c := http.Client{}
req, err := http.NewRequest("PUT", discordgo.EndpointApplicationGlobalCommands(*id), nil)
if err != nil {
panic(err)
}
req.Header.Add("Authorization", "Bot "+os.Getenv("BOT_TOKEN"))
resp, err := c.Do(req)
if err != nil {
panic(err)
}
bytes, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(bytes))
}