-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
38 lines (27 loc) · 986 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import discord
from discord.ext import commands
from transformers import pipeline
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix="!", intents=intents)
pipe = pipeline("image-classification", model="model")
@bot.event
async def on_ready():
print(f"We have logged in as {bot.user}")
@bot.event
async def on_message(message):
if message.author.bot:
return # Ignore messages from bots
# Check if the message has attachments
if message.attachments:
image_url = message.attachments[0].url
result = analyze_image(image_url)
if result[0]['label'] == 'no_safe':
await message.delete()
await message.channel.send(f"{message.author.mention}, detected adult content. The image has been deleted.")
return
await bot.process_commands(message)
def analyze_image(image_url):
return pipe(image_url)
# bot.run("YOUR_BOT_TOKEN")
bot.run("API_KEY")