简体   繁体   English

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

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

Ummm, So I am in dier need of help. 嗯,所以我非常需要帮助。 I am wanting to make it where my bot blocks certain channels from having links being sent. 我想让它在我的机器人阻止某些渠道发送链接的地方使用。 Like, The general channel. 喜欢,一般频道。 I dont want links to be sent there but in #advertisment i dont mind. 我不希望链接发送到那里,但我不介意在#advertisment中。 What do i do about that? 我该怎么办?

This will find if the message contains a URL and is in your discussion channel. 这将查找消息是否包含URL并在您的讨论频道中。 You can get a channels ID by either typing \\#ChannelName in any chat in your channel or by right-clicking on it and selecting "Copy ID". 您可以通过在\\#ChannelName的任何聊天中键入\\#ChannelName或右键单击该频道并选择“复制ID”来获取频道ID。 If you want only URLs in #advertisment you could do message.channel.id != "advertisment 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