-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
57 lines (42 loc) · 1.42 KB
/
bot.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
import discord
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio
import random
import requests
import os
client = commands.Bot(command_prefix="+")
player_dict = dict()
@client.event
async def on_ready():
print("Bot is ready")
@client.command(pass_context=True)
async def play (ctx, url):
channel = ctx.message.author.voice_channel
await client.join_voice_channel(channel)
server = ctx.message.server
voice = client.voice_client_in(server)
player = await voice.create_ytdl_player(url)
player_dict[server.id] = player
await client.send_message(ctx.message.channel, "Playing `%s` now" % player.title)
player.start()
@client.command(pass_context=True)
async def stop(ctx):
server = ctx.message.server
player = player_dict[server.id]
player.stop()
await client.send_message(ctx.message.channel, "Stopped `%s`" % player.title)
del player_dict[server.id]
@client.command(pass_context=True)
async def pause(ctx):
server = ctx.message.server
player = player_dict[server.id]
player.pause()
await client.send_message(ctx.message.channel, "Paused `%s`" % player.title)
@client.command(pass_context=True)
async def resume(ctx):
server = ctx.message.server
player = player_dict[server.id]
player.resume()
await client.send_message(ctx.message.channel, "Resumed `%s`" % player.title)
client.run(str(os.environ.get('BOT_TOKEN')))