简体   繁体   中英

Ban command on message discord.py

import discord
from discord.ext import commands

client = commands.Bot(command_prefix='sk?')

token = ""

@client.event
async def on_message():
    if 'WORD' in message.content:
        await member.ban(reason = WORD)

client.run(token)

I get the error "takes 0 positional arguments but 1 was given" and I don't know what is wrong with my code.

I tried adding on_message(member): and member = message.author() above if 'WORD' in message.content:

I have no idea what to do or what I did wrong.

It also says that for all messages which is really annoying.

on_message takes the message argument, also member should be message.author

@client.event
async def on_message(message):
    if "WORD" in message.content:
        await message.author.ban(reason="WORD")

    # Remember to add `process_commands`
    await client.process_commands(message)

You should also add process_commands at the end of the event so commands work

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