modtools.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:aryas 作者: lattkkthxbbye 项目源码 文件源码
def clear(self, ctx: commands.Context, number: int, member: discord.Member = None) -> None:
        """
        Purges messages from the channel
        :param ctx: The message context
        :param number: The number of messages to purge
        :param member: The member whose messages will be cleared
        """

        if number < 1:
            await command_error(ctx, "You must attempt to purge at least 1 message!")
            return

        def predicate(msg: discord.Message) -> bool:
            return msg == ctx.message or member is None or msg.author == member

        if number <= 100:
            #  Add 1 to limit to include command message, subtract 1 from the return to not count it.
            msgs = await self.bot.purge_from(ctx.message.channel, limit=number + 1, check=predicate)
            send(self.bot, '{} message{} cleared.'.format(len(msgs) - 1, "s" if len(msgs) - 1 != 1 else ""),
                 ctx.message.channel, True)
        else:
            await command_error(ctx, 'Cannot delete more than 100 messages at a time.')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号