Test pointer panic

master
DustyP 6 years ago
parent a0a6b9b54d
commit 87f67569d2

@ -105,7 +105,7 @@ func (c *CommandManager) OnMessage(session *discordgo.Session, m *discordgo.Mess
return return
} }
if !CheckPermissions(session, *m.Member, *channel, command.RequiredPermissions) { if !CheckPermissions(session, m.Author.ID, *channel, command.RequiredPermissions) {
embed := &discordgo.MessageEmbed{ embed := &discordgo.MessageEmbed{
Title: "Insufficient Permissions", Title: "Insufficient Permissions",
Description: "You don't have the correct permissions to run this command.", Description: "You don't have the correct permissions to run this command.",

@ -22,13 +22,13 @@ func GetDefaultStatusManager() StatusManager {
} }
// CheckPermissions checks the channel and guild permissions to see if the member has the needed permissions // CheckPermissions checks the channel and guild permissions to see if the member has the needed permissions
func CheckPermissions(session *discordgo.Session, member discordgo.Member, channel discordgo.Channel, perms Permission) bool { func CheckPermissions(session *discordgo.Session, memberID string, channel discordgo.Channel, perms Permission) bool {
if perms == 0 { if perms == 0 {
return true // If no permissions are required then just return true return true // If no permissions are required then just return true
} }
for _, overwrite := range channel.PermissionOverwrites { for _, overwrite := range channel.PermissionOverwrites {
if overwrite.ID == member.User.ID { if overwrite.ID == memberID {
if overwrite.Allow&int(perms) != 0 { if overwrite.Allow&int(perms) != 0 {
return true // If the channel has an overwrite for the user then true return true // If the channel has an overwrite for the user then true
} else if overwrite.Deny&int(perms) != 0 { } else if overwrite.Deny&int(perms) != 0 {
@ -37,6 +37,11 @@ func CheckPermissions(session *discordgo.Session, member discordgo.Member, chann
} }
} }
member, err := session.State.Member(channel.GuildID, memberID)
if err != nil {
fmt.Println(err)
return false
}
for _, roleID := range member.Roles { for _, roleID := range member.Roles {
role, err := session.State.Role(channel.GuildID, roleID) role, err := session.State.Role(channel.GuildID, roleID)
if err != nil { if err != nil {

Loading…
Cancel
Save