Omega Wolf
Omega Wolf

Reputation: 27

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)

Upvotes: 0

Views: 473

Answers (1)

šeki
šeki

Reputation: 153

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

Upvotes: 2

Related Questions