Discord 'on_member_join' function not working

佐手、 提交于 2021-01-28 13:37:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!