Reputation: 81
I have tried to make a Discord bot which prints the user joining or leaving to the console. However it seems like it's not triggering my Bot. Here's my code:
Here is my current code
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():
print("{member} hat den Server betreten.")
```@client.event
async def on_member_remove():
print("{member} hat den Server verlassen.")
client.run('My Token')
Can someone please help me?
Upvotes: 1
Views: 200
Reputation: 2415
Events that use on_member_join
or others related to member events, must require member intents to be enabled. This works to allow these events to run as they are private and should be used carefully.
Intents can be enabled from Discord developer portal, from there you only need to make sure you have enabled Member
in intents within the "Bot" category. You'd then need to define and use the intents in your bot code in the section you define your bot or client:
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix='your bot prefix', intents=intents)
Upvotes: 1