在删除的消息上返回消息

时间:2020-10-27 22:53:30

标签: python discord discord.py

所以我想在某人在此频道写信时添加一条消息

代码

@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)

我是否仅将ctx添加到on_message(message)并使用ctx.send完成它?

2 个答案:

答案 0 :(得分:1)

您可以使用channel.send将消息发送到特定频道。

@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)

答案 1 :(得分:0)

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)```