-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot_player.py
129 lines (93 loc) · 2.71 KB
/
bot_player.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
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
import discord
from discord.ext.commands import Bot
import youtube_dl
from discord.utils import get
from discord import FFmpegPCMAudio
import os
import asyncio
from dotenv import load_dotenv
load_dotenv()
client = Bot(command_prefix='#')
token = os.getenv('TOKEN') # replace this with token
voice = None
song_list = []
@client.event
async def on_ready():
print("-------Bot is ready -------")
@client.command()
async def greet(ctx):
await ctx.channel.send('hello world..')
@client.command()
async def join(ctx):
channel = ctx.author.voice.channel
global voice
voice = await channel.connect()
@client.command()
async def leave(ctx):
await ctx.voice_client.disconnect()
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
'outtmpl': 'ac12.mp3',
'noplaylist': 'True',
}
playing = False
async def play_list(ctx, song_list):
print(song_list)
if ctx.voice_client.is_playing() == True:
await play_list(ctx, song_list)
elif(len(song_list) > 0):
os.system('youtube-dl ytsearch:'+song_list.pop(-1) +
' --max-downloads 1 --no-playlist --no-part -x -o "bbb.mp3"')
source = FFmpegPCMAudio('bbb.opus')
player = await ctx.voice_client.play(source)
await player.start()
async def play_next(ctx, song_list, client):
asyncio.run_coroutine_threadsafe(
play_list(ctx, song_list), client.loop)
async def loop():
while True:
print()
await asyncio.sleep(3)
client.loop.create_task(loop())
@client.command()
async def sound(ctx, *args):
if args[0] is None:
await ctx.channel.send("no song specified..")
if ctx.voice_client is None:
await ctx.channel.send("Connect to audio channel first")
else:
# if ctx.voice_client is not None:
# ctx.voice_client.stop()
if os.path.exists('ac12.mp3'):
os.remove('ac12.mp3')
if len(args) > 1:
search = args[0] + args[1]
else:
search = args[0]
song_list.append(search)
await ctx.channel.send(search + " added to list")
some = ctx.voice_client.is_playing()
await play_next(ctx, song_list, client)
@client.command()
async def pause(ctx):
playing = False
ctx.voice_client.pause()
@client.command()
async def resume(ctx):
playing = True
ctx.voice_client.resume()
@client.command()
async def stop(ctx):
playing = False
ctx.voice_client.stop()
@client.command()
async def check(ctx):
some = ctx.voice_client.is_playing()
print("some:-", some)
await ctx.channel.send(some)
client.run(token)