#🔒 Can some someone translate this code so I can understand.
20 messages · Page 1 of 1 (latest)
@brittle flicker
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
What code
Looks like I can't send the file,
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
I don't look at it at the moment I'm at work, I will send when I get home
Sorry didn't see the add file button XD
Anyway any help will be much appreciated 👍
PKU�Z(m����bot.pyimport discord
import os
import requests
from bs4 import BeautifulSoup
import json
import asyncio
TOKEN = "YOUR_DISCORD_BOT_TOKEN"
DOWNLOAD_FOLDER = "downloaded_models"
HISTORY_FILE = "download_history.json"
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
Load or create download history
if os.path.exists(HISTORY_FILE):
with open(HISTORY_FILE, "r") as f:
download_history = json.load(f)
else:
download_history = []
def save_history():
with open(HISTORY_FILE, "w") as f:
json.dump(download_history, f)
def download_file(url, folder=DOWNLOAD_FOLDER):
if not os.path.exists(folder):
os.makedirs(folder)
local_filename = os.path.join(folder, url.split("/")[-1].split("?")[0])
if os.path.exists(local_filename):
return None # Already downloaded locally
try:
with requests.get(url, stream=True) as r:
r.raise_for_status()
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
return local_filename
except Exception as e:
print(f"Failed to download {url}: {e}")
return None
def extract_blend_links_from_blendswap(url):
# Basic scraping example for blendswap search or model page
# This is a demo; real site scraping may require login and more headers
try:
headers = {"User-Agent": "Mozilla/5.0"}
r = requests.get(url, headers=headers)
r.raise_for_status()
soup = BeautifulSoup(r.text, "html.parser")
links = []
# Look for direct .blend download links
for a in soup.find_all("a", href=True):
href = a['href']
if href.endswith(".blend") or href.endswith(".zip") or href.endswith(".rar"):
if href.startswith("http"):
links.append(href)
else:
in as {client.user}")
@client.event
async def on_message(message):
if message.author == client.user:
return
content = message.content.strip()
if content.startswith("!download_url"):
parts = content.split(" ", 1)
if len(parts) != 2:
await message.channel.send("Usage: !download_url <url>")
return
url = parts[1].strip()
await download_from_url(url, message.channel)
elif content.startswith("!download_tag"):
# Placeholder: For demo just send not implemented
await message.channel.send("Feature !download_tag is not implemented yet.")
client.run(TOKEN)
PKU�Z� ��� README.md# Discord Blender Model Downloader Bot
This bot downloads free Blender models from URLs you provide.
Features
- Command
!download_url <url>: Downloads Blender.blendor archive files from the given URL. - Keeps track of downloaded URLs to avoid duplicates.
- Stores downloaded files locally in
downloaded_modelsfolder.
Requirements
- Python 3.8+
- Install dependencies:
pip install discord.py requests beautifulsoup4
Setup
- Create a Discord bot and get its token.
- Replace
YOUR_DISCORD_BOT_TOKENinbot.pywith your bot token. - Run the bot:
python bot.py - Use the command in Discord:
!download_url <url>
Notes
- Currently supports basic scraping for Blender model links.
- Extend
extract_blend_links_from_blendswapinbot.pyto support more websites. !download_tagcommand is planned but not implemented yet.
PKU�Z�P�H##requirements.txtdiscord.py
requests
beautifulsoup4
PKU�Z(m������bot.pyPKU�Z� ��� ���README.mdPKU�Z�P�H##���requirements.txtPK��
I think I pasted it all I might of accidentally deleted some lines
Here's the translation: This looks like a Discord bot that downloads Blender model files
Thank you for your quick response,
He's said I need to change some stuff to get it to work.
Any suggestions on what that might be ?
Reading the "Setup" section may help
That would make sense, 😂 again thank you for looking at it for me.
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.