Reputation: 57
I want it so that it autodeletes the author's message (*answer84) after it is typed, here is my code:
@client.command()
async def on_message(message):
await client.process_commands(message)
if message.content.startswith('*answer84'):
await ctx.message.delete()
For some reason it just doesn't delete the message,(there is no traceback error message) any help would be greatly appreciated, thanks!
Upvotes: 0
Views: 130
Reputation: 468
There are just a few errors with your code:
You need to use the event
decorator rather than a command()
decorator. This is "A decorator that registers an event to listen to.". Read more about event references here.
Since the on_message
event only takes in message
as a parameter, there is no such thing as ctx
. Remove the ctx
, and it works!
@client.event #changed decorator to event
async def on_message(message):
if message.content.startswith('*answer84'):
await message.delete() #removed ctx
await client.process_commands(message)
Moved client.process_commands
to the bottom of the event, good practice to do so.
Upvotes: 3