#๐ Discord Music Bot
12 messages ยท Page 1 of 1 (latest)
@desert sparrow
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.
k
import discord
import os
import asyncio
import yt_dlp
from dotenv import load_dotenv
def run_bot():
load_dotenv()
TOKEN = os.getenv('discord_token')
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
queues = {}
voice_clients = {}
yt_dl_options = {"format": "bestaudio/best"}
ytdl = yt_dlp.YoutubeDL(yt_dl_options)
ffmpeg_options = {'options': '-vn'}
@client.event
async def on_ready():
print(f'{client.user} is now jamming')
@client.event
async def on_message(message):
if message.content.startswith("?play"):
try:
voice_client = await message.author.voice.channel.connect()
voice_clients[voice_client.guild.id] = voice_client
except Exception as e:
print(e)
try:
url = message.content.split()[1]
loop = asyncio.get_event_loop()
data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=False))
song = data['url']
player = discord.FFmpegPCMAudio(song, **ffmpeg_options)
voice_clients[message.guild.id].play(player)
except Exception as e:
print(e)
if message.content.startswith("?pause"):
try:
voice_clients[message.guild.id].pause()
except Exception as e:
print(e)
if message.content.startswith("?resume"):
try:
voice_clients[message.guild.id].resume()
except Exception as e:
print(e)
if message.content.startswith("?stop"):
try:
voice_clients[message.guild.id].stop()
await voice_clients[message.guild.id].disconnect()
except Exception as e:
print(e)
client.run(TOKEN)
!yt-dl
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)
I have restarted my computer, everything is working now, Thanks
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.
๐ Discord Music Bot