0

When I try to get the user's display name it returns their Discord name. No matter what method I try display_name is never part of the return list.

Just to make sense of it, if the user mentions someone with "no ping" in their display name, it will go through all the channels in the server looking for mentions in the last 10 minutes.

    for i in range(len(message.mentions)):  # Unimportant, just for clarity
        if "no ping" in message.mentions[i].display_name.lower() or \  # Unimportant, just for clarity
                "unavailable" in message.mentions[i].display_name.lower() or \  # Unimportant, just for clarity
                "unavailable" in message.mentions[i].display_name.lower():  # Unimportant, just for clarity


            counter = 0
            text_channel_list = []
            for TextChannel in message.guild.channels:
                if str(TextChannel.type) == 'text':
                    text_channel_list.append(TextChannel.id)

            prev = datetime.datetime.now() - datetime.timedelta(minutes=10)

            for i in range(len(text_channel_list)):
                channel = client.get_channel(text_channel_list[i])
                msg = await channel.history(limit=None, after=prev).flatten()
                for message2 in msg:
                    if message2.author == message.author:
                        for i in range(len(message2.mentions)):
                            print(message2.mentions[i].display_name)  # This will return the user's Discord name, I want it to return the Server display name.
                            if "no ping" in message2.mentions[i].display_name.lower():
                                counter += 1

1 Answer 1

0

I just encountered this issue and fixed it by expanding the scope of intents to all:

client = discord.Client(intents=discord.Intents.all())

Hope this helps someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.