Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
fix: Guild.MembersByName causes nil panic (close #463)
Browse files Browse the repository at this point in the history
  • Loading branch information
andersfylling committed Dec 29, 2021
1 parent 471b292 commit aecdcbf
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion guild.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,11 @@ func (g *Guild) Member(id Snowflake) (*Member, error) {
}

// MembersByName retrieve a slice of members with same username or nickname
// Will skip checking username of members missing user data.
// The user data might be missing due to cache misses.
func (g *Guild) MembersByName(name string) (members []*Member) {
for _, member := range g.Members {
if member.Nick == name || member.User.Username == name {
if member.Nick == name || (member.User != nil && member.User.Username == name) {
members = append(members, member)
}
}
Expand Down

0 comments on commit aecdcbf

Please sign in to comment.