Better error handling
This commit is contained in:
parent
26e931f44f
commit
0130ec538c
1 changed files with 13 additions and 23 deletions
|
@ -48,29 +48,19 @@ func (cm *CooldownManager) CheckCooldown(userID, commandName string) (bool, time
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckAndApplyCooldown(s *discordgo.Session, i *discordgo.InteractionCreate, commandName string, duration time.Duration) bool {
|
func CheckAndApplyCooldown(s *discordgo.Session, i *discordgo.InteractionCreate, commandName string, duration time.Duration) bool {
|
||||||
cooldownManager := GetCooldownManager()
|
cooldownManager := GetCooldownManager()
|
||||||
user, err := GetUser(i)
|
user, err := GetUser(i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
RespondWithError(s, i, "Error processing command: "+err.Error())
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
return false
|
||||||
Data: &discordgo.InteractionResponseData{
|
}
|
||||||
Content: "Error processing command: " + err.Error(),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
canUse, remaining := cooldownManager.CheckCooldown(user.ID, commandName)
|
canUse, remaining := cooldownManager.CheckCooldown(user.ID, commandName)
|
||||||
if !canUse {
|
if !canUse {
|
||||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
RespondWithError(s, i, fmt.Sprintf("You can use this command again in %v", remaining.Round(time.Second)))
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
return false
|
||||||
Data: &discordgo.InteractionResponseData{
|
}
|
||||||
Content: fmt.Sprintf("You can use this command again in %v", remaining.Round(time.Second)),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
cooldownManager.SetCooldown(user.ID, commandName, duration)
|
cooldownManager.SetCooldown(user.ID, commandName, duration)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue