Reputation: 62
So I am trying to make my bot leave welcome and removed messages using discord.py.
import discord
from discord.ext import commands
import random
client = commands.Bot(command_prefix = '.')
@client.event
async def on_member_join(ctx, *, member):
channel = member.server.get_channel("channel id")
fmt = 'Welcome to the {1.name} Discord server, {0.mention}'
await ctx.send_message(channel, fmt.format(member, member.server))
@client.event
async def on_member_remove(ctx, *, member):
channel = member.server.get_channel("channel id")
fmt = '{0.mention} has left/been kicked from the server.'
await ctx.send_message(channel, fmt.format(member, member.server))
client.run('client id')
The error
File "C:\python\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
TypeError: on_member_join() missing 1 required keyword-only argument: 'member'
comes up.
I am not sure why it isn't working. I have very little experience with it, so I am not sure what I am doing wrong. Could anyone tell me what I am missing?
Upvotes: 0
Views: 16044
Reputation: 1207
@client.event
async def on_member_join(member):
await client.get_channel(idchannel).send(f"{member.name} has joined")
@client.event
async def on_member_remove(member):
await client.get_channel(idchannel).send(f"{member.name} has left")
also keep in mind that idchannel is int, not string
Upvotes: 1
Reputation: 144
@client.event
async def on_member_join(member):
await client.get_channel(idchannel).send(f"{member.name} has joined")
@client.event
async def on_member_remove(member):
await client.get_channel(idchannel).send(f"{member.name} has left")
On event you can't get ctx, because it isn't a command, who must write. It is event
Upvotes: 3