Нужна помощь в музыкальном боте для дискорда

qgboi

Новичок
Пользователь
Сен 24, 2021
2
0
1
Код:
import discord
import nacl
import ffmpeg
from discord import FFmpegPCMAudio
from discord.utils import get
from youtube_dl import YoutubeDL
import os
from discord.ext import commands

client = discord.Client()


@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client)) #Просто проверка на запуск
await client.change_presence(status=discord.Status.online, activity=discord.Game('!help'))



async def join(message):
##Connect to channel
connection = message.author.guild.voice_client
idUserChannel = message.author.voice.channel.id
idBotChannel = 0
if connection:
idBotChannel = client.voice_clients[0].channel.id
if (connection) and (idBotChannel != idUserChannel):
await message.channel.send('**Moving to** ' + str(message.author.voice.channel))
await connection.move_to(message.author.voice.channel)
elif (idBotChannel != idUserChannel):
await message.channel.send('**Я подключился к - ** ' + str(message.author.voice.channel))
await message.author.voice.channel.connect()




async def play(video_link, voice, message):
##Воспроизведение песенок
ydl_opts = {'format': 'bestaudio', 'noplaylist':'True'}
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
with YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(video_link, download = False)
print(info.get('title'))
URL = info['formats'][0]['url']
voice.play(FFmpegPCMAudio(URL, **FFMPEG_OPTIONS), after = lambda e: myAfter(voice, message))
voice.is_playing()
await message.channel.send('**Сейчас играет** - ' + info.get('title'))

async def myAfter(voice, message):
coro = await musicQueue(voice, message)
asyncio.run_coroutine_threadsafe(coro).result()


async def skip(voice, message):
##Skip
voice.stop()
await serverQueue(voice, message)


async def resume(ctx):
await ctx.channel.purge(limit=1)
"Воспроизводит аудио"
voice = discord.utils.get(client.voice_clients,guild=ctx.guild)

if voice.is_paused():
voice.resume()


async def pause(ctx):
async def pause(self, ctx):
current_guild = utils.get_guild(self.bot, ctx.message)
if current_guild is None:
await utils.send_message(ctx, config.NO_GUILD_MESSAGE)
return
if current_guild.voice_client is None or not current_guild.voice_client.is_playing():
return
current_guild.voice_client.pause()



##Queue
queue = []


async def serverQueue(voice, message):
if queue != [] and not voice.is_playing():
await play(queue.pop(0), voice, message)
print('Очередь - ' + str(queue))



@client.event
async def on_message(message):
if message.author == client.user:
return

if message.content.startswith('!' + 'join'):
await join(message)

##Connect and play
if message.content.startswith('!' + 'play'):
await join(message)
voice = get(client.voice_clients, guild=message.channel.guild)
msg = message.content[1:].split()
video_link = msg[1]
if not voice.is_playing():
await play(video_link, voice, message)
else:
await message.channel.send('Добавлено в очередь')
queue.append(video_link)

##Skip
if message.content.startswith('!' + 'skip'):
voice = get(client.voice_clients, guild=message.channel.guild)
await message.channel.send('**Скипнуто**')
await skip(voice, message)


##Resume

if message.content.startswith('!' + 'resume'):
voice = get(client.voice_clients, guild=message.channel.guild)
await message.channel.send('**Продолжаем**')
await resume(voice, message)

##Pause

if message.content.startswith('!' + 'pause'):
voice = get(client.voice_clients, guild=message.channel.guild)
await message.channel.send('**Паузим**')
await pause(voice, message)


client.run('token')
Почему то не работают команды !pause и !resume
И после окончания песни новая из очереди не включается сама, а только через команду !skip

Если кто знает как исправить, помогите пожалуйста. Буду очень благодарен
 
Последнее редактирование:

regnor

Модератор
Команда форума
Модератор
Июл 7, 2020
2 580
457
83
код вставляйте как код, подробнее тут как задать вопрос
 

Форум IT Специалистов