add command play

This commit is contained in:
BFlow 2020-04-29 17:35:32 +02:00
parent 75b32ef3fb
commit 033c187396

View file

@ -1,22 +1,24 @@
# -*- coding: utf-8 -*-
"""Main module."""
import random
import discord
import os
import requests
import aiocron
import asyncio
import discord
import giphy_client
import gitlab
import lxml
import os
import random
import requests
import youtube_dl
from __future__ import unicode_literals
from bs4 import BeautifulSoup as bs
from discord.ext import tasks, commands
from giphy_client.rest import ApiException
from pathlib import Path
from subprocess import *
from sys import argv
from pathlib import Path
from giphy_client.rest import ApiException
from bs4 import BeautifulSoup as bs
here = os.path.dirname(os.path.abspath(__file__))
@ -41,6 +43,8 @@ class Mybot(commands.Cog):
self.sounds_history.reverse()
if len(self.sounds_history) > 5:
self.sounds_history = self.sounds_history[:5]
if audio_file.startswith('/tmp'):
os.remove(audio_file)
#Fin des fonctions necesaire pour Kabot.
#Les commandes pour interagir avec Kabot.
@ -255,6 +259,21 @@ class Mybot(commands.Cog):
await asyncio.sleep(1)
await ctx.channel.send("Tu peux reparler %s!" % member.mention)
@commands.command(help="Jouer un song a partir d'une video")
async def play(self, ctx, lien):
ydl_opts = {'format': 'bestaudio/mp3', 'outtmpl': '/tmp/discord_%(title)s-%(id)s.%(ext)s',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([lien])
info_dict = ydl.extract_info(url, download=False)
out_file = ydl.prepare_filename(info_dict)
self.sounds.append(out_file)
@commands.command()
async def repeat(self, ctx):
# if ctx.message.author.name == self.bot.user.name: