-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprefroma_finale.py
More file actions
158 lines (134 loc) · 4.63 KB
/
prefroma_finale.py
File metadata and controls
158 lines (134 loc) · 4.63 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import discord
from discord.ext import commands
import yt_dlp as youtube_dl
import os
import asyncio
import nest_asyncio
nest_asyncio.apply()
from spotdl import Spotdl
BOT_TOKEN = "YOUR TOKEN"
CHANNEL_REPLAY = "Where the bot write"
yt_dl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
ytdl = youtube_dl.YoutubeDL(yt_dl_opts)
ffmpeg_options = {'options': "-vn"}
spotdl = Spotdl(client_id='your-client-id', client_secret='your-client-secret')
command_prefix = "$"
bot = commands.Bot(command_prefix=command_prefix, intents=discord.Intents.all())
@bot.event
async def on_ready():
print("Hello! i'm ready!")
# channel = bot.get_channel(CHANNEL_ID)
# await channel.send("Hello! i'm ready!")
@bot.command()
async def play(ctx, url : str):
'''
$play link, bot dont have the queue yet
'''
channel = bot.get_channel(CHANNEL_REPLAY)
if ctx.author.voice== None:
await channel.send("join a channel")
return
# await channel.send("your song is start soon")
if "https://" not in url:
await ctx.send("use a link from YouTube or Spotify")
return
if "list=" in url or "playlist" in url:
await ctx.send("playlist link are not suported yet")
return
if "spotify" in url:
# await ctx.send("spotify link are not suported yet")
song_there = os.path.isfile("song.mp3")
try:
if song_there:
os.remove("song.mp3")
except PermissionError:
await ctx.send("wait the end of the song or $help to see other command")
return
await channel.send("your song is start soon")
voiceChannel = discord.utils.get(ctx.guild.voice_channels, name='General')
try:
await voiceChannel.connect()
except Exception:
pass
voice = discord.utils.get(bot.voice_clients, guild=ctx.guild)
songs = spotdl.search([url])
song = songs[0].name
artis = songs[0].artist
# # results = spotdl.download_songs(songs)
sp_dw(songs)
for file in os.listdir("./"):
if file.endswith(".mp3"):
os.rename(file, "song.mp3")
voice.play(discord.FFmpegPCMAudio("song.mp3"))
return
if "youtube" in url:
song_there = os.path.isfile("song.mp3")
try:
if song_there:
os.remove("song.mp3")
except PermissionError:
await ctx.send("wait the end of the song or $help to see other command")
return
await channel.send("your song is start soon")
voiceChannel = discord.utils.get(ctx.guild.voice_channels, name='General')
try:
await voiceChannel.connect()
except Exception:
pass
voice = discord.utils.get(bot.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"))
async def sp_dw(songs):
path, song = spotdl.download(songs[0])
return song
@bot.command()
async def pause(ctx):
'''
Pause the music at that specific time
'''
voice = discord.utils.get(bot.voice_clients, guild=ctx.guild)
try:
voice.pause()
except Exception:
await ctx.send("Currently no audio is playing.")
@bot.command()
async def resume(ctx):
'''
Resume the music at the time you have stop with the command $pause
'''
voice = discord.utils.get(bot.voice_clients, guild=ctx.guild)
try:
voice.resume()
except Exception:
await ctx.send("The audio is not paused.")
@bot.command()
async def stop(ctx):
'''
Disconnect the bot
'''
voice = discord.utils.get(ctx.guild.voice_channels, name=ctx.author.voice.channel)
try:
# await voice.disconnect()
await ctx.voice_client.disconnect(force=True)
except Exception:
await ctx.send("The bot is not connected to a voice channel.")
bot.run(BOT_TOKEN)