Marcus Lindfors
Marcus Lindfors

Reputation: 15

Return message on deleted message

So i want to add a message when someone writes in this channel

Code

@bot.event
async def on_message(message):
    formats = ['jpg', 'png', 'gif', 'svg']
    attachments = [f for f in message.attachments if f.filename.split('.')[-1] in formats]
    if message.channel.name == 'bild' and not attachments:
        await message.delete()
    
    await bot.process_commands(message)

Do I only add ctx to the on_message(message) and finish it of with ctx.send?

Upvotes: 0

Views: 80

Answers (2)

Marcus Lindfors
Marcus Lindfors

Reputation: 15

async def on_message(message):
   formats = ['jpg', 'png', 'gif', 'svg']
   attachments = [f for f in message.attachments if f.filename.split('.')[-1] in formats]
   if message.author == bot.user:
       return
   if message.channel.name == 'dps-test' and not attachments: 
       await message.delete()
       await message.channel.send('Här kan du endast lägga upp bild på ditt DPS-Test, text med bilden funkar.')
       
   await bot.process_commands(message)```

Upvotes: 0

Nurqm
Nurqm

Reputation: 4743

You can use channel.send to send a message to a specific channel.

@bot.event
async def on_message(message):
    formats = ['jpg', 'png', 'gif', 'svg']
    attachments = [f for f in message.attachments if f.filename.split('.')[-1] in formats]
    if message.channel.name == 'bild' and not attachments:
        await message.delete()
        await message.channel.send('You cannot send message without an image.')
    
    await bot.process_commands(message)

Upvotes: 1

Related Questions