【问题标题】:Return message on deleted message已删除消息的返回消息
【发布时间】:2021-02-10 07:13:10
【问题描述】:

所以我想在有人在这个频道写文章时添加一条消息

代码

@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 完成它?

【问题讨论】:

  • “当有人在这个频道写信时我想添加一条消息”是什么意思?您要向该频道发送消息吗?
  • 是的,向那个频道发送一条消息说,你不能只发送文本,类似的东西

标签: python discord discord.py


【解决方案1】:
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)```

【讨论】:

    【解决方案2】:

    您可以使用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)
    

    【讨论】:

    • 啊,顺序错误,但现在它发布一条消息,但删除它并无限循环
    猜你喜欢
    • 1970-01-01
    • 2013-02-01
    • 1970-01-01
    • 2018-06-29
    • 2021-11-13
    • 2015-02-18
    • 1970-01-01
    • 1970-01-01
    • 2019-12-27
    相关资源
    最近更新 更多