Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
514 views
in Technique[技术] by (71.8m points)

python - Discord 'on_member_join' function not working

My on_member_join doesnt seem to work. I wanted my bot to say out the names of the members that joined the sever but it doesnt detect if someone has joined or left.

import discord
from discord.ext import commands

client = commands.Bot(command_prefix = '.')

@client.event
async def on_ready():
    print("bot is ready ")

@client.event
async def on_member_join(member):
    print(f'{member.name} has joined this server')

@client.event
async def on_member_remove(member):
    print(f'{member}was removed')

client.run('*************************')

It is printing "bot is ready" on the terminal so the bot is working. But isn't detecting members leaving or joining pls help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

1 Answer

0 votes
by (71.8m points)

You're probably using discord python 1.5.0 or above, it's a common error, you just need Intents. If there's a error, you are supposed to read it, it will redirect you to your bot in the discord dev portal, there you can activate the privileged gateway intents check this out

And add this to your code

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

client = commands.Bot(command_prefix='.', intents=intents)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
...