fixed error when no autojoinroles are set

This commit is contained in:
2024-03-17 23:08:14 +01:00
parent 1f1c16ca4e
commit 4200215f5f
3 changed files with 16 additions and 7 deletions

View File

@@ -9,8 +9,6 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
var fileData []byte
var cmd_form Command = Command{ var cmd_form Command = Command{
Definition: discordgo.ApplicationCommand{ Definition: discordgo.ApplicationCommand{
Name: "form", Name: "form",

View File

@@ -159,8 +159,11 @@ func messageDelete(s *discordgo.Session, m *discordgo.MessageDelete) { //TODO: a
} }
func guildMemberJoin(s *discordgo.Session, m *discordgo.GuildMemberAdd) { func guildMemberJoin(s *discordgo.Session, m *discordgo.GuildMemberAdd) {
err := s.GuildMemberRoleAdd(m.GuildID, m.User.ID, getAutoJoinRole(m.GuildID, m.User.Bot)) role := getAutoJoinRole(m.GuildID, m.User.Bot)
if role != "" {
err := s.GuildMemberRoleAdd(m.GuildID, m.User.ID, role)
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
} }
}
} }

View File

@@ -319,10 +319,18 @@ func getAutoJoinRole(guildID string, isBot bool) string {
} else { } else {
isBotString = "user" 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)
return role
}
if exists {
err = db.QueryRow("SELECT "+isBotString+"_role FROM autojoinroles WHERE guild_id = $1", guildID).Scan(&role)
if err != nil { if err != nil {
logrus.Error(err, guildID) logrus.Error(err, guildID)
} }
}
return role return role
} }