Learning objectives
After reading this article you will be able to:
- Understand why YouTube stopped working in music bots
- Identify which error and which library your bot uses
- Choose between fragile workarounds and alternative audio sources
If your music bot played YouTube without trouble and suddenly started answering with errors, the fault is almost never in your code. YouTube offers no official way for Discord bots to pull audio from it, so every music bot depends on libraries that imitate a YouTube client. When YouTube changes something, they break.
The topic is volatile: before you act, check your library's documentation for its current state.
Why did the bot stop playing YouTube?#
Three factors add up.
- Terms of service. YouTube's terms forbid accessing the service by automated means (robots, botnets, scrapers) without prior written permission. They also forbid circumventing or interfering with the service's security features and downloading content unless the service allows it. In 2021, after requests from Google, large bots such as Groovy and Rythm shut down (Groovy and Rythm, in The Verge).
- Automation detection. YouTube flags requests that look automated and answers with blocks such as the sign-in prompt.
- Changes to clients and deciphering. Libraries pose as YouTube clients (web, Android, TV) and solve JavaScript challenges. When a client stops working, the library breaks until someone ships a fix.
Which error do you see?#
The symptom depends on the library. The most common one:
Sign in to confirm you're not a botThat is the automation block. The README of youtube-source, Lavalink's YouTube plugin, describes exactly this case and says OAuth and poToken may help, but are not a guaranteed fix.
Other signs: a search that comes back empty, a track that loads and ends within seconds, or a bot that joins the voice channel and stays silent. Since each library reports problems differently, the diagnosis starts with finding out which one you use.
How do you find out which library the bot uses?#
| If your project uses | Status |
|---|---|
| discord-player v7 | The YouTube extractor was removed. The docs say YouTube playback was discontinued because extraction libraries break so often. The library still detects links, but neither plays them nor extracts metadata. |
| Lavalink with the built-in YouTube source | Disabled in the recommended configuration and replaced by the youtube-source plugin. |
| Lavalink with youtube-source | Update the plugin and review the client list. |
| yt-dlp (directly or through a wrapper) | Update yt-dlp and install a JavaScript runtime. |
| Old, unmaintained extraction packages | Switch to one of the options above or to another source. |
How do you try to fix it with Lavalink?#
This section and the next summarize what each project's documentation says. None of these tweaks makes the use compliant with YouTube's terms.
If you use Lavalink v4, disable the built-in source (the Lavalink docs mark it as deprecated) and use the plugin. Replace VERSION with the version shown on the Releases tab of youtube-source:
lavalink:
server:
password: "change-this-password"
sources:
youtube: false
plugins:
- dependency: "dev.lavalink.youtube:youtube-plugin:VERSION"
snapshot: false
plugins:
youtube:
enabled: true
allowSearch: true
allowDirectVideoIds: true
allowDirectPlaylistIds: true
clients:
- MUSIC
- ANDROID_VR
- WEB
- WEBEMBEDDEDClients are tried in list order. A few points from the plugin's documentation:
MUSICis for search only (theytmsearch:prefix), not for playback.- The
ANDROIDclient is described as heavily restricted and often broken. PreferANDROID_VRand the others.TVrequires sign-in to play. TVHTML5EMBEDDEDwas removed in version 1.18.0 because it stopped working for playback.TVHTML5_SIMPLYtook its place.- poToken only applies to
WEBandWEBEMBEDDED. OAuth only applies toTV. You don't need one if you use the other. - Remote deciphering is supported (
remoteCipher), with a separate server, yt-cipher.
After changing application.yml, restart Lavalink and read the logs to see which client failed.
How do you try to fix it with yt-dlp?#
yt-dlp now requires a JavaScript runtime to solve YouTube's challenges, through the EJS project's scripts. Deno is recommended and enabled by default; Node.js also works if you enable it with --js-runtimes. The minimum version of each runtime is in the documentation.
When the default clients fail, the extractors page suggests the mweb client with a PO Token, which yt-dlp cannot generate on its own (wiki).
Are cookies or OAuth worth it?#
It is the most cited workaround and the riskiest. youtube-source warns that OAuth can get the account terminated, recommends burner accounts and notes that under heavy traffic it can cause rate-limit errors. yt-dlp says using your account raises the risk of a ban. Never use your personal account.
One point no code solves: the terms of service question remains. Running a public bot that pulls audio from YouTube is a risky decision, and it is the responsibility of whoever runs the bot.
What alternatives are there?#
- Other Lavalink sources, such as SoundCloud, Bandcamp, Twitch, Vimeo and HTTP links, which the server ships with (Lavalink configuration). Each service has its own terms of use.
- Your own files or direct audio links that you have the right to play.
- Services with an official audio API, respecting each one's terms.
- Accepting the fragility: keep the plugin updated, monitor the bot and tell your users when YouTube fails.
Pin a version of the plugin or library in production and follow its releases. When YouTube changes again, the fix usually ships as a new release, and your job is to apply it. To understand the audio piece behind all this, see what Lavalink is.
How to do this on Square Cloud#
On Square Cloud, a music bot runs like any other Discord bot: you deploy it by ZIP upload in the dashboard, the CLI, GitHub or the VS Code extension, with discord.js, discord.py, JDA or another Gateway library. Voice is supported and FFmpeg is available in the container.
Lavalink runs as a separate web application in the same account (from 512 MB), and the bot connects to its subdomain on port 443 with a secure connection (secure: true). That way you update the YouTube plugin by restarting only Lavalink. The plan's RAM is a pool shared across your applications, with a minimum of 256 MB per background app. Environment variables (such as the Lavalink password) live in the dashboard and apply on the next restart.
None of this changes what YouTube decides to block: hosting keeps the process online, but what the bot does with YouTube remains the responsibility of whoever runs it. For the step-by-step deploy, see how to host a discord.js bot. To see what's available for bots, visit the Discord bots on Square Cloud page.
Bot hosting
Keep your bot online 24/7 with automatic restarts
FAQs
Why won't my Discord music bot play YouTube anymore?
YouTube blocks automated requests and changes its clients often, which breaks the libraries that extract the audio. In some cases the library was discontinued, like the YouTube extractor in discord-player v7.
What does 'Sign in to confirm you're not a bot' mean?
It is YouTube blocking requests it classifies as automated. The Lavalink and yt-dlp projects mention OAuth and poToken as workarounds, but neither is guaranteed.
Will updating the library fix it?
Sometimes, when the problem is a change that a new release already fixed. If the library was discontinued, updating does not help: you need a different solution or a different source.
Is it safe to use a Google account in the bot?
No. youtube-source itself warns that OAuth login can get the account terminated and recommends burner accounts. yt-dlp gives a similar warning about cookies.
More in Bots
See all 33 articles- How much does it cost to host a Discord bot?The cost of hosting a Discord bot depends on RAM, uptime, database and outside services. Learn how to estimate your own bill and where the money goes.
- Running a bot on your phone or PC vs hosting itA bot on your PC or phone (Termux) goes offline when the device shuts down, sleeps or loses its network. Compare the three options and when each one fits.
- How to host a Discord bot 24/7To keep a Discord bot online 24/7, run its process on an always-on machine with automatic restarts. Compare your PC, a VPS with pm2 or systemd, and bot hosting.
- Why your Discord bot keeps going offline (and how to fix it)A Discord bot goes offline when the process dies, the token is invalid, an intent is disabled or memory runs out. Learn to diagnose each cause and fix it.