make command global
This commit is contained in:
parent
ac3d3c204b
commit
2a3ec00b58
2 changed files with 29 additions and 7 deletions
|
@ -23,9 +23,10 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
token = os.Getenv("disgo_token")
|
||||
apiImgurKey = os.Getenv("disgo_imgur")
|
||||
registerGuildID = snowflake.GetEnv("disgo_guild_id")
|
||||
token = os.Getenv("disgo_token")
|
||||
apiImgurKey = os.Getenv("disgo_imgur")
|
||||
globalComandsEnv = os.Getenv("disgo_global")
|
||||
registerGuildID = snowflake.GetEnv("disgo_guild_id")
|
||||
|
||||
// TODO: add jokes
|
||||
commands = []discord.ApplicationCommandCreate{
|
||||
|
@ -83,6 +84,8 @@ var (
|
|||
},
|
||||
},
|
||||
}
|
||||
|
||||
noCommands []discord.ApplicationCommandCreate
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -110,8 +113,27 @@ func main() {
|
|||
|
||||
defer client.Close(context.TODO())
|
||||
|
||||
if _, err = client.Rest().SetGuildCommands(client.ApplicationID(), registerGuildID, commands); err != nil {
|
||||
log.Fatal("error while registering commands: ", err)
|
||||
var globalComands bool
|
||||
if strings.ToUpper(globalComandsEnv) == "TRUE" {
|
||||
globalComands = true
|
||||
}
|
||||
|
||||
if globalComands {
|
||||
if _, err = client.Rest().SetGlobalCommands(client.ApplicationID(), commands); err != nil {
|
||||
log.Fatal("error while registering commands: ", err)
|
||||
}
|
||||
if registerGuildID != 0 {
|
||||
if _, err = client.Rest().SetGuildCommands(client.ApplicationID(), registerGuildID, noCommands); err != nil {
|
||||
log.Info("error deleting guild commands", err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if _, err = client.Rest().SetGuildCommands(client.ApplicationID(), registerGuildID, commands); err != nil {
|
||||
log.Fatal("error while registering commands: ", err)
|
||||
}
|
||||
if _, err = client.Rest().SetGlobalCommands(client.ApplicationID(), noCommands); err != nil {
|
||||
log.Info("error deleting global commands", err)
|
||||
}
|
||||
}
|
||||
|
||||
if err = client.OpenGateway(context.TODO()); err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue