[英]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.