Bugfix, new functional
This commit is contained in:
parent
63ab1e0ec2
commit
6de9fd7d4a
1 changed files with 50 additions and 10 deletions
|
@ -2,6 +2,7 @@ import os
|
||||||
import asyncio
|
import asyncio
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
from discord.utils import get
|
||||||
from youtubesearchpython import VideosSearch
|
from youtubesearchpython import VideosSearch
|
||||||
from pytube import YouTube
|
from pytube import YouTube
|
||||||
|
|
||||||
|
@ -9,18 +10,19 @@ from pytube import YouTube
|
||||||
# https://discord.com/api/oauth2/authorize?client_id=861599847441104926&permissions=2184277249&scope=bot
|
# https://discord.com/api/oauth2/authorize?client_id=861599847441104926&permissions=2184277249&scope=bot
|
||||||
|
|
||||||
# Options
|
# Options
|
||||||
|
prefs__music_channel = 'Музыка'
|
||||||
token = '*** YOUR TOKEN ***'
|
token = '*** YOUR TOKEN ***'
|
||||||
bot = commands.Bot(command_prefix='/')
|
bot = commands.Bot(command_prefix='/')
|
||||||
|
|
||||||
# Command /catplay <search query>
|
# Command /catplay <search query>
|
||||||
@bot.command(name='catplay', description='Plays the music in a voice channel')
|
@bot.command()
|
||||||
async def catplay(ctx, *args):
|
async def catplay(ctx, *args):
|
||||||
|
|
||||||
# Get the server (guild) and the music channel
|
# Get the server (guild) and the music channel
|
||||||
curserver = ctx.guild
|
curserver = ctx.guild
|
||||||
music_channel = None
|
music_channel = None
|
||||||
for vch in curserver.voice_channels:
|
for vch in curserver.voice_channels:
|
||||||
if (vch.name == 'Музыка'):
|
if (vch.name == prefs__music_channel):
|
||||||
music_channel = vch
|
music_channel = vch
|
||||||
|
|
||||||
if (music_channel != None):
|
if (music_channel != None):
|
||||||
|
@ -39,18 +41,56 @@ async def catplay(ctx, *args):
|
||||||
notif = discord.Embed(color=0xe3813e, title='Playing:', description=f'{yt.author} - {yt.title}')
|
notif = discord.Embed(color=0xe3813e, title='Playing:', description=f'{yt.author} - {yt.title}')
|
||||||
notif.set_image(url=yt.thumbnail_url)
|
notif.set_image(url=yt.thumbnail_url)
|
||||||
|
|
||||||
# Connecting to the voice channel
|
await ctx.send(':inbox_tray: **Connecting...**')
|
||||||
sp = await music_channel.connect()
|
|
||||||
# Stopping previously playing music
|
# Get the VoiceClient and connect to the channel
|
||||||
if (sp.is_playing()):
|
vc = get(bot.voice_clients, guild=curserver)
|
||||||
sp.stop()
|
if vc and vc.is_connected():
|
||||||
|
await vc.move_to(music_channel)
|
||||||
|
else:
|
||||||
|
vc = await music_channel.connect()
|
||||||
# Playing music to the voice channel
|
# Playing music to the voice channel
|
||||||
sp.play(discord.FFmpegPCMAudio(source='music.mp3'), after=None)
|
vc.play(discord.FFmpegPCMAudio(source='music.mp3'), after=None)
|
||||||
await ctx.send(embed=notif)
|
await ctx.send(embed=notif)
|
||||||
while (sp.is_playing()):
|
while vc.is_playing():
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
sp.stop()
|
if vc.is_playing():
|
||||||
|
vc.stop()
|
||||||
os.remove('music.mp3')
|
os.remove('music.mp3')
|
||||||
|
|
||||||
|
# Command /catpause
|
||||||
|
@bot.command()
|
||||||
|
async def catpause(ctx):
|
||||||
|
curserver = ctx.guild
|
||||||
|
music_channel = None
|
||||||
|
for vch in curserver.voice_channels:
|
||||||
|
if (vch.name == prefs__music_channel):
|
||||||
|
music_channel = vch
|
||||||
|
|
||||||
|
if (music_channel != None):
|
||||||
|
vc = get(bot.voice_clients, guild=curserver)
|
||||||
|
await vc.move_to(music_channel)
|
||||||
|
if (vc.is_paused()):
|
||||||
|
vc.resume()
|
||||||
|
await ctx.send(':arrow_forward: **Playing**')
|
||||||
|
else:
|
||||||
|
vc.pause()
|
||||||
|
await ctx.send(':pause_button: **Paused**\n> To resume the playback, type the command /catpause again.')
|
||||||
|
|
||||||
|
# Command /catstop
|
||||||
|
@bot.command()
|
||||||
|
async def catstop(ctx):
|
||||||
|
curserver = ctx.guild
|
||||||
|
music_channel = None
|
||||||
|
for vch in curserver.voice_channels:
|
||||||
|
if (vch.name == prefs__music_channel):
|
||||||
|
music_channel = vch
|
||||||
|
|
||||||
|
if (music_channel != None):
|
||||||
|
vc = get(bot.voice_clients, guild=curserver)
|
||||||
|
await vc.move_to(music_channel)
|
||||||
|
vc.stop()
|
||||||
|
await ctx.send(':stop_button: **Stopped**')
|
||||||
|
|
||||||
# Starting bot after setup
|
# Starting bot after setup
|
||||||
bot.run(token)
|
bot.run(token)
|
||||||
|
|
Loading…
Add table
Reference in a new issue