on_member_join does not work, Discord.py

Asked

Viewed 226 times

-1

I was developing a bot and then I decided to create a feature that would receive members and send a short message in your DM.

I made the following code:

Instance of the Client class:

client = discord.Client()

Function on_member_join

@client.event
async def on_member_join(member):
    await member.send(
        f'Olá {member.name}, bem vindo ao server!'
    )

But the code didn’t work. I made sure that the argument guild_subscriptions was valuable True and I’m in the version 1.5.1.

What may have occurred and how I could solve this problem?

  • Caue, mold the rest of the code you are using, as Voce is creating the variable client?

1 answer

0


To send a DM for the user you need to first create a private chat with the user and then send a message to that channel.

@client.event
async def on_member_join(member):
    await member.create_dm()  # cria um chat privado
    await member.dm_channel.send(  # envia a mensagem para o chat privado
        f'Olá {member.name}, bem vindo ao server!'
    )

References:

  • Hello, even applying what you said, the code continued not working

Browser other questions tagged

You are not signed in. Login or sign up in order to post.