'on_member_join(member) is never called in discord.py

I am making a discord bot with discord.py on python 3.8.6.

My other functions, such as on_ready and other commands, work. However, on_member_join is never called when a member joins.

from discord.ext import commands
bot = commands.Bot(command_prefix =".")

@bot.event
async def on_ready():
    print('logged on salaud')

@bot.event
async def on_member_join(member):
    print("test")

bot.run("TOKEN")

Why is on_member_join not being called, and how can I resolve this?



Solution 1:[1]

discord.py v1.5 introduces intents

An intent basically allows a bot to subscribe into specific buckets of events.

In order to be able to get server data you need to:

  • Enable Server Member intents in your application enter image description here

  • And Implement discord.Intents at the beginning of your code.

import discord

intents = discord.Intents.all()


bot = discord.Client(intents=intents)

# or 

from discord.ext import commands
bot = commands.Bot(command_prefix = ".", intents=intents)


For more information, read about Intents | documentation

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wavened