mpetkov19
mpetkov19

Reputation: 21

Search Members Function

Currently this function is searching for a member that starts with the input query. For example, if i input ja, it will output all members that have their names start with ja. However, i am trying to make it so it accounts for all names that have ja in their name. Hence, it will not only include jack, jasper but include kaja, maja etc.

    @staticmethod
    async def search_members(guild, member) -> typing.List[discord.Member]:

        return [i for i in guild.members if str(i).lower().startswith(member.lower())]

Upvotes: 0

Views: 149

Answers (1)

Mihito
Mihito

Reputation: 155

You can use the in keyword.

@staticmethod
async def search_members(guild, member) -> typing.List[discord.Member]:

    return [i for i in guild.members if member.lower() in str(i).lower()]

NOTE: This looks up the Members username if you want the Nickname of the Member in this specific guild use discord.Member.display_name

Upvotes: 1

Related Questions