How to get the longest user name? (discord.py)

Viewed 2842

I have a list of users ID, and I want to find the user with the longest name. But when I use bot.get_user(id) it returns None. I checked the ID, it is valid and does correspond to a user on the server. Code:

            for score in scores:
                bad_chars = "<@!>"
                for letter in score:
                    if letter in bad_letters:
                        score = score.replace(letter, "")

                print(score)
                print(bot.get_user(int(score.strip("<@! >"))))
                member_len = bot.get_user(int(score.strip("<@ >")))

                if member_len:
                    print(len(member_len.name))
                    if len(member_len.name) > score_len:
                        score_len = len(member_len.name)

            print(score_len)
1 Answers

In the new version of discord.py(1.5.x), there're some updates about Intents. Intents are similar to permissions, you have to define Intents to get channels, members and some events etc. You have to define it before defining the client = discord.Bot(prefix='').

import discord

intents = discord.Intents().all()
client = discord.Bot(prefix='', intents=intents)

If you want to get more information about Intents, you can look at the API References.

Related