簡體   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