【问题标题】:Discord Python bot that deletes messages in a certain channel which are not commandsDiscord Python bot 删除某个频道中不是命令的消息
【发布时间】:2020-12-04 03:37:27
【问题描述】:

所以我有一个#support 频道,我的不和谐成员可以在其中输入 =support,机器人会向他们发送消息以帮助他们,之后机器人将删除用户在频道中输入的 =support 命令以保留频道清理,但是在这个频道中,他们也可以输入任何不是命令的消息,机器人不会删除它,如果不是命令,机器人有没有办法删除消息?

【问题讨论】:

标签: python discord


【解决方案1】:

这可以使用on_message来完成

@bot.event
async def on_message(m):
    if m.channel.id == ChannelIDOfSupport Channel:
        if m.content.replace(bot.prefix, "") not in [i.name for i in bot.commands]:
            await m.delete()

【讨论】:

    【解决方案2】:

    所以基本上我所做的就是替换消息侦听器的实际命令,如果它从支持执行命令开始,那么我恢复了命令功能。它看起来像这样:

    async def on_message(m):
        if m.channel.id == 735866701069025301:
    
            if m.content.startswith('=ticket'):
    
                await m.author.send('Your ticket will be created according to what you choose, use the = before choosing a number and then put the number next to it (Example: =2) \n \n **1. General Support** \n \n **2. Staff Application**')
                await m.channel.purge()
    
            else: {
                await m.delete()
    }
        await client.process_commands(m)
    

    下面的代码有些功能,但是,我所有的@client.command 或@bot.command 如果你愿意,都不能正常运行,不是你的错@Poojan,我没有粘贴代码所以你不知道是否我使用的是命令而不是事件。 上面的代码完美运行,感谢您的帮助,也感谢您的帮助@Xetera,我按照代码进行了一些研究并得出了这个结论:)

    vvvvvvvvvvvv 这个答案对我帮助很大。

    【讨论】:

      猜你喜欢
      • 2020-10-01
      • 2021-06-30
      • 2018-09-07
      • 2020-08-25
      • 2018-11-07
      • 2021-01-10
      • 1970-01-01
      • 1970-01-01
      • 2018-07-24
      相关资源
      最近更新 更多