-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.py
53 lines (41 loc) · 1.58 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
import discord
import re
import time
import youtube_dl
token = 'Mjk0MTM1Mjg0MjczMjUwMzA1.C7QukQ.gSdGLmWXhKsvjHf9CYgYfCQQfPw'
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as', client.user.name)
discord.opus.load_opus('libopus-0.dll')
print('Opus loaded =', discord.opus.is_loaded())
@client.event
async def on_message(message: discord.Message):
#if message.author == client.user.name:
# return
usr = message.author
print(usr, message.content) # chatlogger
if message.content.startswith('--join'):
urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', message.content)
if len(message.attachments) > 0:
urls = [message.attachments[0]['url']]
join_channel = usr.voice.voice_channel
print(join_channel)
voice = await client.join_voice_channel(join_channel)
player = await voice.create_ytdl_player(urls[0])
player.start()
global millisecond
global ping
if message.content.startswith('ping'):
millisecond = int(round(time.time() * 1000))
print(millisecond)
await client.send_message(message.channel, 'pong')
print (client.user)
if message.content.startswith('pong') and message.author == client.user:
ping = int(round(time.time() * 1000))
print (ping)
print (ping - millisecond)
await client.send_message(message.channel, ping - millisecond)
if (message.content.startswith('leave')):
await discord.VoiceClient.disconnect()
client.run(token)