#๐ Error: 'NoneType' object has no attribute 'lower'
30 messages ยท Page 1 of 1 (latest)
@granite scroll
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.
import discord
from discord.ext import commands
import yt_dlp as ytdl
import os
import re
import string
Define your intents
intents = discord.Intents.default()
intents.message_content = True
Set up bot command prefix
bot = commands.Bot(command_prefix='!', intents=intents)
Helper function to clean the filename by removing unsupported characters
def clean_filename(filename):
valid_chars = f"-_.() {string.ascii_letters}{string.digits}"
return ''.join(c for c in filename if c in valid_chars)
Function to download YouTube video with flexible quality
def download_youtube_video(url):
try:
# Options for yt-dlp
ydl_opts = {
'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4', # Tries best MP4 format
'outtmpl': './%(title)s.%(ext)s', # Save in current directory
'noplaylist': True,
'merge_output_format': 'mp4',
'postprocessors': [{
'key': 'FFmpegVideoConvertor',
}],
}
with ytdl.YoutubeDL(ydl_opts) as ydl:
# Extract video info
info_dict = ydl.extract_info(url, download=True)
if 'title' not in info_dict:
return None, "Error: Could not extract video title."
video_title = info_dict.get('title', None)
if not video_title:
return None, "Error: Video title is empty or could not be extracted."
# Clean the title to make it a valid filename
video_title_clean = clean_filename(video_title)
video_path = f"./{video_title_clean}.mp4" # Ensure the file is saved in the current directory
Check if the file exists
if os.path.exists(video_path):
return video_path, video_title_clean
else:
return None, "Download failed; file not found."
except Exception as e:
return None, f"Error: {str(e)}"
@bot.event
async def on_ready():
print(f'Logged in as {bot.user}')
@bot.command(name='download')
async def download_video(ctx, url: str):
# Validate YouTube link
if not re.match(r'^(https?://)?(www.)?(youtube.com|youtu.be)/', url):
await ctx.send("Invalid YouTube link.")
return
await ctx.send("Downloading video... This may take a while.")
video_path, message = download_youtube_video(url)
# Check for error in extracting title or video path
if video_path is None:
await ctx.send(message)
return
# Ensure message is not None
if message is None:
await ctx.send("Error: No video title extracted.")
return
try:
# Change the bot's display name in the server to the video title (max 32 characters)
video_title = message[:32]
try:
await ctx.guild.me.edit(nick=video_title) # Change bot's nickname
except Exception as e:
print(f"Failed to change bot's nickname: {str(e)}")
await ctx.send(f"Failed to change bot's nickname: {str(e)}")
# Send the video file to Discord
await ctx.send(file=discord.File(video_path, filename=f"{message}.mp4"))
except Exception as e:
await ctx.send(f"Error: {str(e)}")
finally:
# Clean up the downloaded file after sending
if os.path.exists(video_path):
os.remove(video_path)
Add your bot token here
bot.run('Token Here')
!paste
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.
So you want to take an existing YT video, and copy it to your own channel as an MP4, is that right?
is that right?
!rule 5
5. Do not provide or request help on projects that may violate terms of service, or that may be deemed inappropriate, malicious, or illegal.
100%
!rule 5
5. Do not provide or request help on projects that may violate terms of service, or that may be deemed inappropriate, malicious, or illegal.
it's not wrong i just want to promote my channel on onther channel that i own
your project violates rule 5, we can't help sorry
you own channel but dont own the videos 
are you okay is your mind okay
i said i want to promote my own videos
MY OWN
i dont see how what he said is wrong
if the other channels are also yours, you should have the video too , you dont need to use ytdlp to download an existing video off of youtube
!ytdlp
Per Python Discord's Rule 5, we are unable to assist with questions related to youtube-dl, pytube, or other YouTube video downloaders, as their usage violates YouTube's Terms of Service.
For reference, this usage is covered by the following clauses in YouTube's TOS, as of 2021-03-17:
The following restrictions apply to your use of the Service. You are not allowed to:
1. access, reproduce, download, distribute, transmit, broadcast, display, sell, license, alter, modify or otherwise use any part of the Service or any Content except: (a) as specifically permitted by the Service; (b) with prior written permission from YouTube and, if applicable, the respective rights holders; or (c) as permitted by applicable law;
3. access the Service using any automated means (such as robots, botnets or scrapers) except: (a) in the case of public search engines, in accordance with YouTubeโs robots.txt file; (b) with YouTubeโs prior written permission; or (c) as permitted by applicable law;
9. use the Service to view or listen to Content other than for personal, non-commercial use (for example, you may not publicly screen videos or stream music from the Service)
read 
we dont help with any kind of project that uses libraries like ytdlp
ASS COMMUNITY
<@&831776746206265384>
/i_don't_give_a_fuck_about_rules_
lol
!close
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.