僵尸无法识别消息在初始发送后约5秒后被删除(服务器消息删除)。

问题描述 投票:0回答:1

我有一个不需要的小功能,我的机器人不能识别消息是否在最初发送后5秒后被删除。以下是我的代码,用于记录被删除的消息。

@commands.Cog.listener()
async def on_message_delete(self, c):
    if(c.guild):
        if c.guild.name == "Server Name":
            if c.author.bot == True:
                print(f"{c.created_at} || Bot: {c.author} deleted --- {c.content} --- in #{c.channel}");
            else:
                print(f"{c.created_at} || User: {c.author} deleted --- {c.content} --- in #{c.channel}");

我知道在文档中,有一个叫做 "max messages "的值,它与 "on_message_delete "联系在一起。我无法成功地实现它。我正在寻找服务器范围内的日志,例如,如果有人删除了5天前的消息。如果这是一个选项

python bots discord.py
1个回答
0
投票

使用下面的事件可能会有一些帮助,因为它不需要消息在缓存中。

@commands.Cog.listener()
async def on_raw_message_delete(self, payload):
    if payload.guild_id:
        guild = self.bot.get_guild(payload.guild_id)
        channel = self.bot.get_channel(payload.channel_id)
        message = await channel.fetch_message(payload.message_id)
        if guild.name == "Server Name":
            if message.author.bot: # more pythonic way of checking bools
                print(...
            else:
                print(...

引用:


0
投票
@commands.Cog.listener()
    async def on_message_delete(self, c):
        if(c.guild):
            if c.guild.name == "Sniper's lounge":
                if c.author.bot == True:
                    print(f"Bot: {c.author} deleted --- {c.clean_content} --- in #{c.channel.name}");
                    pass;
                else:
                    print(f"User: {c.author} deleted --- {c.clean_content} --- in #{c.channel.name}");
                    pass;
            elif c.guild.name == "New GAR":
                if c.author.bot == True:
                    print(f"Bot: {c.author} deleted --- {c.clean_content} --- in #{c.channel.name}");
                    pass;
                else:
                    print(f"User: {c.author} deleted --- {c.clean_content} --- in #{c.channel.name}");
                    pass;
        else:
            pass;
© www.soinside.com 2019 - 2024. All rights reserved.