Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- from discord.ext import commands
- import os
- import youtube_dl
- client = commands.Bot(command_prefix="!")
- ## komendy ktore potrzebujemy
- # play
- # stop
- # pause
- # resume
- # leave
- # skip
- # loop?
- # add w wersji 3
- @client.event
- async def on_ready():
- print("Bot jest gotowy.")
- @client.command()
- async def play(ctx, url : str):
- song = os.path.isfile("song.mp3")
- try:
- if song:
- os.remove("song.mp3")
- except PermissionError:
- await ctx.send("Piosenka jeszcze leci! Użyj komendy stop.")
- return
- voiceChannel = discord.utils.get(ctx.guild.voice_channels, name="rozmówki")
- await voiceChannel.connect()
- voice = discord.utils.get(client.voice_clients, guild=ctx.guild)
- ydl_opts = {
- 'format': 'bestaudio/best',
- 'postprocessors': [{
- 'key': 'FFmpegExtractAudio',
- 'preferredcodec': 'mp3',
- 'preferredquality': '192',
- }],
- }
- with youtube_dl.YoutubeDL(ydl_opts) as ydl:
- ydl.download([url])
- for file in os.listdir("./"):
- if file.endswith(".mp3"):
- os.rename(file, "song.mp3")
- voice.play(discord.FFmpegPCMAudio("song.mp3"))
- client.run("your_token")
Advertisement
Add Comment
Please, Sign In to add comment