我希望能够检测不和谐用户何时发送 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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!