Reputation: 3
I made discord bot that should give someone role upon joining but I get error which can be seen here:
Traceback (most recent call last):
File "C:\Users\jarda\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\client.py", line 409, in _run_event
await coro(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
TypeError: on_member_join() missing 2 required positional arguments: 'after' and 'member'
And almost full code is here:
import discord
from discord.ext import commands
from discord.utils import get
from discord.ext.commands import Bot
intents = discord.Intents.all()
client = commands.Bot(command_prefix="!", intents=intents)
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
@client.event
async def on_message(message):
if message.content.startswith("AboutMe"):
await message.channel.send("Hello world!")
@client.event
async def on_member_join(before, after, member):
channel=client.get_channel(channelID)
emb=discord.Embed(title="New member has joined",description=f"Thanks {member.mention} for being part of the bros!")
await channel.send(embed=emb)
print(f"{member.name} has joined the server")
#Adds role
TheGreatLegendWarriors = Bot.get_guild(serverID)
if 'inTraining' in after.roles:
if not 'inTraining' in str(before.roles):
await after.add_roles(discord.utils.get(TheGreatLegendWarriors.roles, name="inTraining"))
print(f"INFO: {after.name} Has been given inTraining role!")
Iam new to py and discord api so really unsure what the issue is. I tried using 2 on_member_join which gave me error as 2 of those can't run at the same time. Then this appeared and I have struggled for way too long now.
Upvotes: 0
Views: 107