如何检查消息内容中的超链接(最好通过 Discord.py)

时间:2023-05-12
本文介绍了如何检查消息内容中的超链接(最好通过 Discord.py)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我希望能够检测不和谐用户何时发送 URL 链接,无论是视频、网站还是不和谐邀请,并保存链接,是否有任何预先存在的库?

I want to be able to detect when a discord user sends a URL link, whether it be a video, website, or discord invite, and to save the link, are there any pre-existing libraries?

推荐答案

Regex 是我最喜欢的解决方案.

Regex is my favourite solution for this.

    def _match_url(url):
        regex = re.compile(
            "(([w]+:)?//)?(([dw]|%[a-fA-fd]{2,2})+(:([dw]|%[a-fA-fd]{2,2})+)?@)?([dw][-dw]{0,253}[dw].)+[w]{2,63}(:[d]+)?(/([-+_~.dw]|%[a-fA-fd]{2,2})*)*(?(&?([-+_~.dw]|%[a-fA-fd]{2,2})=?)*)?(#([-+_~.dw]|%[a-fA-fd]{2,2})*)?"
        )
        if regex.match(url):
            return True
        else:
            return False

这篇关于如何检查消息内容中的超链接(最好通过 Discord.py)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:Client = discord.client() TypeError: 'module' object 下一篇:如何在 Python discord bot 中获取提到的用户的 ID?

相关文章