Ask coding questions

← Back to all posts
How to detect NSFW content in a Google search command?
RobbieWinfield (1)

I'm making a Discord bot using discord.py (Python obviously). One of the commands users can do is a Google search command. When I sent the bot to a publication website so others can add it to their servers, it got declined several times because of an issue where people can search for NSFW content via this command. As of the time I'm making this post, the command starts at line 152 but that's subject to change because I'm actively working on the bot. (Just search for googlesearch if you need to find it). https://VegetarianBot--robbiewinfield.repl.co (yes, I am aware that my name is in the link; just don't kill me in my sleep).

Comments
hotnewtop
cv88 (0)

I don't know exactly how you'd implement it, but google has its own "safeSearch" mode that's designed to filter out certain kinds of very NSFW content. Also not sure if its scope would be wide enough.

RobbieWinfield (1)

@cv88 I think I got it to work by giving the search() function the args safe='on'. Thanks for your response though.