问题
Okay so I'm trying to make a filter for my bot, but one that isn't too complicated. I've got this:
@bot.event
async def on_message(ctx,message):
if 'fuck' in Message.content.lower:
Message.delete()
But it gives the error:
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 270, in _run_event
await coro(*args, **kwargs)
TypeError: on_message() missing 1 required positional argument: 'message'
Could you guys help me out?
Thanks!
回答1:
The on_message event handler only gets passed a single Message object, not a Context object.
回答2:
As you can see here, the delete function has to be awaited.
What I've also noticed in your code is that you are capitalizing message
when the argument to the function passed is lowercase.
@bot.event
async def on_message(message):
if 'fuck' in message.content.lower:
await message.delete()
This should work now.
来源:https://stackoverflow.com/questions/59809874/how-do-i-make-my-bot-delete-a-message-when-it-contains-a-certain-word