Hey everyone, I’m having trouble with my Discord bot. It’s supposed to send a welcome message when someone joins the server, but it’s not working at all. I’ve set up the on_member_join event, but nothing happens when a new user joins. I’ve double-checked my code and permissions, but I can’t figure out what’s wrong. Has anyone else run into this issue before? Any tips on how to troubleshoot or what I might be missing? I’m pretty new to Discord bot development, so any help would be really appreciated!
import discord
client = discord.Client()
@client.event
async def on_ready():
print('Bot is online')
@client.event
async def on_member_join(member):
channel = member.guild.system_channel
if channel:
await channel.send(f'Welcome to the server, {member.mention}!')
client.run('YOUR_BOT_TOKEN')
This is what my code looks like. Am I doing something wrong here?
Have you verified that your bot has the necessary permissions in your server? Sometimes, the issue isn’t with the code but with the bot’s role settings. Ensure your bot’s role is high enough in the hierarchy to view members and send messages in the designated channel. Also, double-check that you’ve invited the bot with the correct scopes, including ‘bot’ and ‘applications.commands’. Lastly, make sure you’re using the latest version of discord.py, as older versions might not support some features. If none of these solve your problem, you might want to consider using a logging system to debug and see if the event is being triggered at all.
hey mate, make sure ur bot has the ‘presence intent’ enabled too. sometimes that’s the culprit. also, try adding some print statements in ur on_member_join function to see if it’s even being triggered. if not, the problem might be with the event listener itself. good luck!
I’ve encountered this issue before, and it’s often related to intents. Discord introduced intents as a way to optimize bot performance, but it can cause headaches if not properly configured.
In your code, you’re using the older discord.Client(). For member events to work, you need to enable the members intent. Try updating your code like this:
Also, make sure you’ve enabled the ‘Server Members Intent’ in the Discord Developer Portal for your bot. It’s under the ‘Bot’ section.
If that doesn’t solve it, double-check your bot’s permissions in the server. It needs to be able to see the channel it’s posting to and have permission to send messages there.
Hope this helps! Let me know if you’re still having trouble after trying these steps.