繁体   English   中英

阻止某些渠道的链接? discord.py

[英]Block links in certain channels? discord.py

嗯,所以我非常需要帮助。 我想让它在我的机器人阻止某些渠道发送链接的地方使用。 喜欢,一般频道。 我不希望链接发送到那里,但我不介意在#advertisment中。 我该怎么办?

这将查找消息是否包含URL并在您的讨论频道中。 您可以通过在\\#ChannelName的任何聊天中键入\\#ChannelName或右键单击该频道并选择“复制ID”来获取频道ID。 如果只需要#advertisment中的URL,则可以执行message.channel.id != "advertisment id"

import re

@client.event
async def on_message(message):
    urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', message.content.lower())
    if url and message.channel.id == "your general channel id"
             await client.delete_message(message)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM