简体   繁体   中英

Discord.py Welcome/Removed messages in chat

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?

@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

@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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM