0

I tried to do something like this randomly, based on the usage of "on_member_join" function, but this didn't work. so, how can I make this work?

@client.event
async def on_member_connect(member):
    channel = discord.utils.get(member.guild.voice_channels, name="channel-name")
    print("blabla")
Kyroic
  • 1
  • 1

1 Answers1

1

As per the docs, on_member_join is not called when a member joins a channel, it is called when a user joins a guild/server.

on_member_connect is not an event on discord.py, what you are looking for is on_voice_state_update.

@client.event
async def on_voice_state_update(member, before, after):
    if before.channel is None and after.channel:
       # User has connected to a VoiceChannel
       channel = after.channel
       # Code here...
Mathias Sven
  • 349
  • 3
  • 7
  • firstly, thank you! And I am sorry but, I couldnt figure it out how to complete this code.. I put a simple print() function where you wrote "# code here..." but it didn't work :/ Can you explain a bit more? – Kyroic Feb 03 '22 at 06:15
  • @Kyroic can *you* explain more? specifically what do you mean by it didn't work? you joined the channel and the message wasn't printed? make sure your [intents](https://stackoverflow.com/a/64832812/13123877) are correctly set-up – Wasi Master Feb 03 '22 at 07:08
  • Yes, when I join the channel, the message is not getting printed. intents = discord.Intents(messages=True, guilds=True, reactions=True, members=True, presences=True) client = commands.Bot(command_prefix="!",intents=intents) And here is my intents setup, is there anything wrong here? I am not sure. @WasiMaster – Kyroic Feb 03 '22 at 18:56
  • 1
    @Kyroic why don't you just do `intents = discord.Intents.all()`. Do that and see what happens – Wasi Master Feb 04 '22 at 13:41
  • 1
    @WasiMaster oh, it's done!! thank you! Intents.all() worked! – Kyroic Feb 04 '22 at 15:37