-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
69 lines (59 loc) · 1.88 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import discord
from discord.ext import commands
import os
import youtube_dl
client = commands.Bot(command_prefix = "!")
@client.command()
async def play(ctx, url : str):
song_there = os.path.isfile("song.mp3")
try:
if song_there:
os.remove("song.mp3")
except PermissionError:
await ctx.send("Usa el comando !stop")
return
voiceChannel = discord.utils.get(ctx.guild.voice_channels, name = 'General')
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.command()
async def leave(ctx):
voice = discord.utils.get(client.voice_clients, guild = ctx.guild)
if voice.is_connected():
await voice.disconnect()
else:
await ctx.send("El bot no está conectado al canal de voz")
@client.command()
async def pause(ctx):
voice = discord.utils.get(client.voice_clients, guild = ctx.guild)
if voice.is_playing():
voice.pause()
else:
await ctx.send("No hay ninguna canción sonando actualmente")
@client.command()
async def resume(ctx):
voice = discord.utils.get(client.voice_clients, guild = ctx.guild)
if voice.is_paused():
voice.resume()
else:
await ctx.send("La canción no está pausada")
@client.command()
async def stop(ctx):
voice = discord.utils.get(client.voice_clients, guild = ctx.guild)
voice.stop()
client.run(os.getenv("TOKEN"))