Online harassment detection faces significant challenges due to its expansive reach and anonymity. Addressing this issue demands effective detection mechanisms capable of processing vast data streams and adapting to evolving online language. Leveraging advancements in artificial intelligence, we propose a novel approach grounded in natural language processing (NLP) and metaheuristic algorithms. Our methodology integrates term frequency-inverse document frequency (TF-IDF) encoding and the AdaBoost algorithm for classification. To tackle the NP-hard problem of hyperparameter selection, we introduce a modified crayfish optimization algorithm (COA), termed GI-COA. This paper represents a pioneering effort in utilizing metaheuristic algorithms for hyperparameter selection in harassment detection models. Through experimentation, we demonstrate the efficacy of our approach in fostering a safer online environment. The best performing optimize models demonstrate and accuracy exceeding 77%.