Reputation:
I'm trying to get my Join/Leave messages working but not sure if i did it right. I tested with a bot user but it threw an error in console. Here is my code:
@commands.Cog.listener()
async def on_member_join(self, ctx, *, member):
ctx.channel = get(ctx.member.guild.channels, name="join-leave")
embed = discord.Embed(color=0x4a3d9a)
embed.add_field(name="Welcome", value=f"{member.name} has joined {member.guild.name}", inline=False)
embed.set_image(url="https://newgitlab.elaztek.com/NewHorizon-Development/discord-bots/Leha/-/raw/master/res/welcome.gif")
await self.client.send_message(ctx.channel, embed=embed)
@commands.Cog.listener()
async def on_member_remove(self, ctx, *, member):
ctx.channel = get(ctx.member.guild.channels, name="join-leave")
embed = discord.Embed(color=0x4a3d9a)
embed.add_field(name="Welcome", value=f"{member.name} has left {member.guild.name}", inline=False)
embed.set_image(url="https://newgitlab.elaztek.com/NewHorizon-Development/discord-bots/Leha/-/raw/master/res/goodbye.gif")
await self.client.send_message(ctx.channel, embed=embed)
and here is the error it threw:
Ignoring exception in on_member_join
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/discord/client.py", line 312, in _run_event
await coro(*args, **kwargs)
TypeError: on_member_join() missing 1 required positional argument: 'member'
Ignoring exception in on_member_remove
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/discord/client.py", line 312, in _run_event
await coro(*args, **kwargs)
TypeError: on_member_remove() missing 1 required positional argument: 'member'
Any help would be much aprreciated. Also I'm on the rewrite branch if that helps.
Upvotes: 0
Views: 5262
Reputation: 311
You only need to pass one parameter for on_member_join as specified in the docs. The easiest way to get the channel is by looping through them and then sending the embed as follows:
@commands.Cog.listener()
async def on_member_join(self, member):
for channel in member.guild.channels:
if str(channel) == "join-leave":
embed = discord.Embed(color=0x4a3d9a)
embed.add_field(name="Welcome", value=f"{member.name} has joined {member.guild.name}", inline=False)
embed.set_image(url="https://newgitlab.elaztek.com/NewHorizon-Development/discord-bots/Leha/-/raw/master/res/welcome.gif")
await channel.send(embed=embed)
Upvotes: 1