Discord Python僵尸程序,它删除特定通道中不是命令的消息

时间:2020-08-14 08:50:47

标签: python discord

因此,我有一个#support频道,我的不和谐成员可以在其中输入= support,并且漫游器会向他们发送消息以帮助他们,之后漫游器将删除用户在该频道中键入的= support命令以保持通道干净,但是他们也可以在该通道中键入不是命令的任何消息,并且漫游器不会删除该消息,如果不是命令,漫游器是否可以删除消息?

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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

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,我按照代码进行了研究,并得出了结论:)

vvvvvvvvvvvvv这个答案对我很有帮助。