Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Check if message contains a link; Discord.py

I want to make a Discord bot that checks messages for potential Discord Nitro scam bots. So far, the relevant code for detection is:

keywords = ["GIFT", "GIFTS", "NITRO", "CATCH", "FOR", "FREE", "@EVERYONE", "@HERE"]
keywords_met = 0
@bot.event
async def on_message(message):
    if message.author == bot.user:
        return
    content = message.content.split()
    print(content)
    for word in content:
        print("Loop iteration")
        if word.upper() in keywords:
            global keywords_met
            keywords_met += 1
    if keywords_met >= 3:
        channel = bot.get_channel(ID of a mod channel)
        await channel.send("<@ID of a role> nitro scam detected")
        keywords_met = 0

Speaking from experience, keywords are words that are often used in those messages. However, I would like to check if the message contains a link, too. The problem is that the URL that the bots send changes frequently, so I can’t check for one specific link.
Is there a way to check for links in general?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use method in to check a substring inside a string.Example:

if 'https://' in word:
    # logic here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading