0

i want to make the user type !join to join in a game but delete all messages in it so it doesn't get full. But when i do this it deletes all the messages in that channel, but it breaks all the other parts of the bot.

I tried await message.delete() and await message.channel.purge(limit=1).

@client.event
async def on_message(message):
    channel = client.get_channel(590978944904331274)
    if message.channel == channel:
        await message.channel.purge(limit=1)


client.run(token)

it works but breaks the rest of the bot.

2 Answers2

0
@client.event
async def on_message(message):
    channel = client.get_channel(590978944904331274)
    if message.channel == channel:
        await message.delete()

or in your !join command if you are using

async def join(ctx):
    #do your code
    await ctx.message.delete()

The await ctx.message.delete() will delete the users message/command when the command is used.

The await message.delete() will delete anyone's message even conversation.

Axisnix
  • 2,822
  • 5
  • 19
  • 41
0

the awnser was

From the documentation:

Overriding the default provided on_message forbids any extra commands from running. To fix this, add a bot.process_commands(message) line at the end of your on_message. For example:

@bot.event
async def on_message(message):
    # do some extra stuff here

    await bot.process_commands(message)

The default on_message contains a call to this coroutine, but when you override it with your own on_message, you need to call it yourself.

@benjin commented this on the post. Thanks.