Home>

I'm trying to get the user byidand send him a message. But the methodget_userreturns an objectLazyUserand hence the message is not sent. The user is friends on the account from which I am trying to send a message.

user= client.get_user(id)
await user.send('hello')

Error:AttributeError: 'LazyUser' object has no attribute 'send'

According to the answers from the net, here is what I tried:

Enablemembersvintentions:

intents= discord.Intents.default()
intents.members= True
client= discord.Client(intents=intents)

UseIntents.all():

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

Get non-cached user data:

user= await client.fetch_user(478250423078223893)
await user.send("hello world")

Error:AttributeError: 'Client' object has no attribute 'fetch_user'

None of this helped.

  • Answer # 1

    get_usergets information about thediscord.Client, that is, about the bot. As far as I know, "getting" a user is only possible viaGuild(server). The following code "gets"name+discriminatoruser by id and sends himHello. If you need more information, then you can "get" the user through enumerationguild.members

    import discord
    token= 'token here'
    intents= discord.Intents.default()
    intents.members= True
    bot= discord.Client(intents=intents)
    @bot.event
    async def on_ready():
        print(f"{bot.user.name}ready")
    @bot.event
    async def on_message(message):
        if message.author.bot is False:
            guild= bot.get_guild( Server ID )
            print(guild.get_member( member ID ))
            user= guild.get_member( Member ID )
            await user.send("Hello")
    bot.run(token)
    
  • Answer # 2

    get_usergets information about thediscord.Client, that is, about the bot. As far as I know, "getting" a user is only possible viaGuild(server). The following code "gets"name+discriminatoruser by id and sends himHello. If you need more information, then you can "get" the user through enumerationguild.members

    import discord
    token= 'token here'
    intents= discord.Intents.default()
    intents.members= True
    bot= discord.Client(intents=intents)
    @bot.event
    async def on_ready():
        print(f"{bot.user.name}ready")
    @bot.event
    async def on_message(message):
        if message.author.bot is False:
            guild= bot.get_guild( Server ID )
            print(guild.get_member( member ID ))
            user= guild.get_member( Member ID )
            await user.send("Hello")
    bot.run(token)