python - url 检测 discord.py
问题描述
urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*(),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+',message.content.lower())
if urls and message.channel.id == "702468264361590828":
await message.channel.send("Links are not allowed in here")
这是我们的 discord.py 机器人的代码,你们在上面看到的命令应该检测是否发送了链接,然后发送消息。但它没有检测到它。我已经print
代替了,await message.channel.send("Links are not allowed in here")
但这也没有用。我什么都进口了。仅供参考,我用它来导入re
:
pip install regex
我找不到一个名为的包re
,所以我使用了这个
解决方案
您不需要导入任何包。re 包(正则表达式)随附已导入的 Python 3。
您的问题是由频道 ID 的字符串版本引起的。频道 ID始终采用 int 形式。所以只需删除周围的引号"702468264361590828"
推荐阅读
- javascript - 使用 setInterval() 的 HTTP 轮询每 1 秒调用一次,而不是提到的间隔
- python - 在easygui multenterbox中不断更新消息框
- apache-kafka-connect - Kafka connect:kafka connect 使用的默认 acks 值是多少?
- sql - 使用 SUBSTRING 和 CHARINDEX 提取部分名称
- powerbi - 在 PowerBI 中将 dBGeography 解析为纬度和经度
- sharepoint - 使用 Graph 对驱动器项目进行多条件查询和过滤
- mips - Verilog。尝试使用 3-AluControl 位扩展数据路径和解码器以进行乘法和 bltz MIPS 指令
- java - 获取 org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector 无法转换为 org.apache.hadoop.hive.ql.exec.vector.LongColumnVector
- pandas - 有条件地删除重复行 - 啄序
- c# - .Net Core 中 NU1605 警告/错误的可能解决方法