简体   繁体   中英

On member join event message doesn't work - discord.py

I'm very new to discord.py , I want to learn python and make a simple bot for my server. I want make a bot that sends a message when someone joins server. But the bot won't send any message. I tried so many solutions but none work.

No error in console. Just 'on_member_join' doesn't work; ping and console message methods work.

Here is my code:

    import discord
    from discord.ext import commands
    
    client = commands.Bot(command_prefix='*')
    TOKEN = '----my token here----'
    
    @client.event
    async def on_ready():
        print('Bot is ready')
    
    @client.event
    async def on_member_join(member):
        channel = client.get_channel(764960656553934879)
        await channel.send('Hello')
    
    @client.command()
    async def ping(ctx):
        await ctx.send('Pong!')
    
    client.run(TOKEN)

For discord.py 1.5.0, reference the introduction of intents .

Your bot will need the members intent - which happens to be a priveleged intent - in order for the on_member_join event to be triggered properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM