diff --git a/scripts/dbMigrate.go b/scripts/dbMigrate/main.go similarity index 100% rename from scripts/dbMigrate.go rename to scripts/dbMigrate/main.go diff --git a/scripts/deleteAllCommands/main.go b/scripts/deleteAllCommands/main.go new file mode 100644 index 0000000..6320917 --- /dev/null +++ b/scripts/deleteAllCommands/main.go @@ -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)) +}