I am trying to make a discord bot with the Discord.py library. The commands with the @client.command() decorator work fine for me, but none of the event ones that I tried work.
JavaScript
x
9
1
@client.event
2
async def on_member_join(member):
3
channel = client.get_channel(ChannelId) #I did define channel Id in my code
4
await channel.send("someone has joined")
5
6
@client.event
7
async def on_member_remove(member):
8
print("Someone has left")
9
I would expect this to output to the terminal or in the channel id I put in, but nothing appears, not even an error message.
*I used client. for all functions. *I am doing this on mac.
Im not quite sure why its working, I do not get any error messages, and I cant seem to find anyone else with this problem.
Thanks in advance
Advertisement
Answer
With version >1.5.0 you can do something like this:
JavaScript
1
11
11
1
import discord
2
3
intents = discord.Intents.default()
4
intents.members = True
5
6
client = discord.Client(intents=intents)
7
8
@client.event
9
async def on_member_join(member):
10
await member.send("Welcome!")
11
You also need to enable intents in the developer portal in https://discord.com/developers/applications. Bot > Bot > Presence & Server Members Intents > Toggle On