Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

My discord bot doesn't seem to be executing a function on member join

I’m new to coding discord bots, so this might be some easy fix mistake I made but when a member joins my server, the bot doesn’t seem to react, be it to add a role or just send a random message in the console.
I’d also add, I’m using replit to host my bot.

import os
import discord
from discord.ext import commands
from replit import db

client = discord.Client()

@client.event
async def on_ready():
  print("I'm in")
  print(client.user)


@client.event
async def on_message(message):
  if message.author == client.user:
    return
  if message.content == "ping":
    await message.channel.send("pong")

@client.event
async def on_member_join(member):
    print("A member has joined")
    role = discord.utils.get(member.server.roles, id="920344130184437931")
    await client.add_roles(member, role)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You need to enable Privileged Gateway Intents in Discord Developer Portal.
When you enable that, you need to type this in your code:

intents = discord.Intents.all()
client = commands.Bot('PREFIX',intents=intents)

@client.event
async def on_ready():
    print("I'm in")
    ....

After that on_member_join event should work

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading