fixed error when no autojoinroles are set
This commit is contained in:
@@ -9,8 +9,6 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var fileData []byte
|
||||
|
||||
var cmd_form Command = Command{
|
||||
Definition: discordgo.ApplicationCommand{
|
||||
Name: "form",
|
||||
|
@@ -159,8 +159,11 @@ func messageDelete(s *discordgo.Session, m *discordgo.MessageDelete) { //TODO: a
|
||||
}
|
||||
|
||||
func guildMemberJoin(s *discordgo.Session, m *discordgo.GuildMemberAdd) {
|
||||
err := s.GuildMemberRoleAdd(m.GuildID, m.User.ID, getAutoJoinRole(m.GuildID, m.User.Bot))
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
role := getAutoJoinRole(m.GuildID, m.User.Bot)
|
||||
if role != "" {
|
||||
err := s.GuildMemberRoleAdd(m.GuildID, m.User.ID, role)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -319,9 +319,17 @@ func getAutoJoinRole(guildID string, isBot bool) string {
|
||||
} else {
|
||||
isBotString = "user"
|
||||
}
|
||||
err := db.QueryRow("SELECT "+isBotString+"_role FROM autojoinroles WHERE guild_id = $1", guildID).Scan(&role)
|
||||
var exists bool
|
||||
err := db.QueryRow("SELECT EXISTS (SELECT 1 FROM autojoinroles WHERE guild_id = $1)", guildID).Scan(&exists)
|
||||
if err != nil {
|
||||
logrus.Error(err, guildID)
|
||||
logrus.Error(err)
|
||||
return role
|
||||
}
|
||||
if exists {
|
||||
err = db.QueryRow("SELECT "+isBotString+"_role FROM autojoinroles WHERE guild_id = $1", guildID).Scan(&role)
|
||||
if err != nil {
|
||||
logrus.Error(err, guildID)
|
||||
}
|
||||
}
|
||||
return role
|
||||
}
|
||||
|
Reference in New Issue
Block a user