Improved error handling
This commit is contained in:
parent
851a7c559c
commit
b76920d697
@ -28,11 +28,13 @@ func Region(s *discordgo.Session, msg *discordgo.MessageCreate) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the channel, this is used to get the guild ID
|
|
||||||
c, _ := s.Channel(msg.ChannelID)
|
|
||||||
|
|
||||||
// Check to see if user already has a region role
|
// Check to see if user already has a region role
|
||||||
user, _ := s.GuildMember(c.GuildID, msg.Author.ID)
|
user, err := s.GuildMember(guildID, msg.Author.ID)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
s.ChannelMessageSend(msg.ChannelID, "Error: User not found")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
for _, role := range user.Roles {
|
for _, role := range user.Roles {
|
||||||
match := false
|
match := false
|
||||||
@ -42,7 +44,7 @@ func Region(s *discordgo.Session, msg *discordgo.MessageCreate) bool {
|
|||||||
for _, id := range regions {
|
for _, id := range regions {
|
||||||
if role == id {
|
if role == id {
|
||||||
// Remove the role and set match to true
|
// Remove the role and set match to true
|
||||||
s.GuildMemberRoleRemove(c.GuildID, msg.Author.ID, id)
|
s.GuildMemberRoleRemove(guildID, msg.Author.ID, id)
|
||||||
match = true
|
match = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -54,7 +56,7 @@ func Region(s *discordgo.Session, msg *discordgo.MessageCreate) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try to set the role
|
// Try to set the role
|
||||||
err := s.GuildMemberRoleAdd(c.GuildID, msg.Author.ID, regions[region])
|
err = s.GuildMemberRoleAdd(guildID, msg.Author.ID, regions[region])
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.ChannelMessageSend(msg.ChannelID, "The region role could not be set!")
|
s.ChannelMessageSend(msg.ChannelID, "The region role could not be set!")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user