0

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())]
mpetkov19
  • 21
  • 3
  • 1
    Does this answer your question? [Does Python have a string 'contains' substring method?](https://stackoverflow.com/questions/3437059/does-python-have-a-string-contains-substring-method) – Łukasz Kwieciński Mar 29 '21 at 16:25

1 Answers1

1

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

Mihito
  • 145
  • 1
  • 4