问题
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.
回答1:
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)
回答2:
i solved this problem to downgrade discord.py
maybe intents option is error.
i'm already using discord api forum intents option but not working
so if u wanna on_member_join and remove events, downgrade your discord.py under version 1.5.0
u type this in console
pip install discord.py==1.4.2
and in your cords remove all about intents cord and activate your cords
that's it.
来源:https://stackoverflow.com/questions/64348389/discord-on-member-join-function-not-working