Repository navigation
YouTube Access
YouTube blocks many VPS and data center IP addresses. When that happens, songs fail with "Sign in to confirm you're not a bot", "HTTP Error 403" or "Audio stream failed". This page shows every fix the bot supports.
- In Discord, users see "YouTube blocked this request (bot detection)".
- In the console, the bot prints a hint for you, at most once every 10 minutes:
YouTube is blocking this server ("Sign in to confirm you're not a bot"). Export YouTube cookies to cookies.txt and set COOKIES_FILE=./cookies.txt in .env (or YOUTUBE_PO_TOKEN / PROXY_URL). See README.md, section "YouTube: Sign in to confirm you're not a bot". - With the SoundCloud fallback on (the default), songs keep playing from SoundCloud and users see "YouTube did not work for this song, so it is playing from SoundCloud." After 3 refused YouTube streams in a row, the bot uses SoundCloud directly for 10 minutes.
Use one of the fixes below. Cookies are the most common one.
Use a YouTube account for this; a secondary account is recommended.
- In Chrome or Edge install the extension "Get cookies.txt LOCALLY" (Firefox: "cookies.txt").
- Open youtube.com, log in, and play any video.
- Click the extension and export the cookies. Save the file as
cookies.txtin the bot folder. - Add this line to
.envand restart the bot:COOKIES_FILE=./cookies.txt
The startup check confirms the file:
[ OK ] YouTube cookies /full/path/to/the/bot/cookies.txt
If the path is wrong it stops with COOKIES_FILE "./cookies.txt" does not exist and shows where it looked.
Warning:
cookies.txtlogs in as your YouTube account. Treat it like a password. It is already listed in.gitignore, so git will not commit it, but never share or upload it.
If the bot runs on the same computer where you use YouTube in a browser, you do not need to export anything:
COOKIES_FROM_BROWSER=chromeSupported values: brave, chrome, chromium, edge, firefox, opera, safari, vivaldi, whale. To use another browser profile, add it after a colon, as yt-dlp expects: COOKIES_FROM_BROWSER=chrome:Profile 1. If both are set, COOKIES_FILE is used.
YOUTUBE_PO_TOKEN=your_po_tokenThe bot passes it to yt-dlp as a YouTube extractor argument. For anything else yt-dlp offers, YTDLP_EXTRACTOR_ARGS adds your own --extractor-args value, for example:
YTDLP_EXTRACTOR_ARGS=youtube:player_client=web_safariA residential proxy gives the bot an IP address that YouTube does not block:
PROXY_URL=http://user:password@host:port-
http://,https://,socks4://,socks5://andsocks5h://work. - Several proxies can be listed with commas:
PROXY_URL=http://proxy-a:8080,http://proxy-b:8080 - YouTube locks each stream to the IP that requested it, so every Discord server always uses the same proxy from the list.
- The proxy is used for YouTube and for every audio download (SoundCloud and direct links too), because all downloads go through yt-dlp.
| Users see | Meaning | Fix |
|---|---|---|
| Age-restricted video | YouTube wants a logged-in account | Use Fix 1 or Fix 2. The song also only plays when the panel's channel is marked age-restricted (NSFW). |
| Geo-blocked content | The video is not available where the bot is hosted | Try another link, or use a proxy (Fix 4). |
| Too many requests (rate limited) | YouTube or another platform is limiting this server | Wait a few minutes. If it keeps happening, use cookies or a proxy. |
| Video unavailable | Private, deleted or not available in this area | Try a different song or link. |
YouTube changes often, and yt-dlp follows. Every time the bot starts, it checks for a new yt-dlp if the last check is more than a day old, and installs it before the shards begin. This fixes most YouTube errors that are not about blocking.
Tip: The check runs only at startup. If your bot runs for weeks without a restart, restart it now and then so yt-dlp stays current. If you set
YTDLP_PATHto your own yt-dlp, keeping it updated is your job.
Back to: Troubleshooting · Configuration
Beatra Music Bot (umutxyp/MusicBot) · MIT License · by Umut Bayraktar · Codeshare
Start here
Using the bot
Running it
Project