Untitled
plain_text
a month ago
2.4 kB
3
Indexable
Never
import discord from discord.ext import commands from pysaucenao import SauceNao # Bot configuration bot_prefix = "!" # Change this to your desired bot prefix token = "xxxx" # Replace with your bot's token CHANNEL_ID = xxxxx # Replace with the ID of the desired channel intents = discord.Intents.default() intents.typing = True intents.presences = True intents.messages = True intents.message_content = True bot = commands.Bot(command_prefix=bot_prefix, intents=intents) # Initialize SauceNao sauce = SauceNao(api_key="xxxxxx") @bot.event async def on_ready(): print(f"Logged in as {bot.user.name}") @bot.event async def on_message(message): # Check if the message is from the desired channel if message.channel.id == CHANNEL_ID: # Check if the message has any image attachments if message.attachments: for attachment in message.attachments: # Check if the attachment is an image if attachment.url.lower().endswith(('png', 'jpg', 'jpeg', 'gif', 'bmp')): try: # Use SauceNao to find the source of the image print(f"Searching for source of {attachment.url}...") results = await sauce.from_url(attachment.url) print(f"Number of results: {len(results)}") if len(results) > 0: source_info = results[0] # Get the first result similarity = source_info.similarity source_url = source_info.source_url print(f"Similarity: {similarity}%") print(f"Source URL: {source_url}") # Send the source information to the same channel await message.channel.send(f"Similarity: {similarity}%\nSource URL: {source_url}") else: print("No source found for this image.") await message.channel.send("No source found for this image.") except Exception as e: print(f"An error occurred: {str(e)}") await message.channel.send(f"An error occurred: {str(e)}") await bot.process_commands(message) # Run the bot bot.run(token)