import discord
from discord.ext import commands
import youtube_dl
intents = discord.Intents().all()
bot = discord.Client()
client = discord.Client(intents=intents)
bot = commands.Bot(command_prefix='!', intents=intents)
YDL_OPTIONS = {'format': 'worstaudio/best',
'noplaylist': 'True', 'simulate': 'True', 'preferredquality': '192', 'preferredcodec': 'mp3', 'key': 'FFmpegExtractAudio'}
class mod(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
async def clear(self, ctx, amount: int): # задаем функцию, т.е. название команды.
messages = await ctx.channel.purge(limit=amount + 1) # пурджим сообщения, +1 т.к. наше тоже удалится
@commands.command() # эмбед в заметки о всех командах
async def cmds(self, ctx):
cmdsembed = discord.Embed(title='` Команды ботa `')
cmdsembed.add_field(name="` Smart commands `", value=">>> `!profil` — посмотреть профиль\n`!avatar` — посмотреть аватар\n`!cmds` — все команды бота", inline=True)
cmdsembed.add_field(name="` Music commands `", value=">>> `!join` — бот зайдет в войс\n`!leave` — бот выйдет из войса", inline=True)
await ctx.send(embed=cmdsembed)
@commands.command()
async def profil(self, ctx):
embed = discord.Embed(title=f"Профиль — {ctx.message.author}") # главный эмбед
embed.add_field(name=">>> Статус: ", value="`Не определен`", inline=True)
embed.set_thumbnail(url=ctx.author.avatar_url) # ава справа квадратная
embed.add_field(name=">>> Баланс: ", value="`0`", inline=True)
embed.add_field(name=">>> Голосовой онлайн: ", value="`0 ч / 0 м`", inline=True)
embed.add_field(name=">>> Возлюбленный/ая: ", value="`нет`", inline=True)
await ctx.send(embed=embed)
@commands.command()
async def avatar(self, ctx):
avaembed = discord.Embed(title = f"Аватар — {ctx.message.author}")
avaembed.set_thumbnail(url=ctx.author.avatar_url)
avaembed.add_field(name=f">>> @{ctx.message.author} ,", value=" ниже `Ваша` аватарка.", inline=True)
avaembed.set_image(url=ctx.author.avatar_url)
await ctx.send(embed=avaembed)
youtube_dl.utils.bug_reports_message = lambda: ''
ytdl_format_options = {
'format': 'bestaudio/best',
'restrictfilenames': True,
'noplaylist': True,
'nocheckcertificate': True,
'ignoreerrors': False,
'logtostderr': False,
'quiet': True,
'no_warnings': True,
'default_search': 'auto',
'source_address': '0.0.0.0' # bind to ipv4 since ipv6 addresses cause issues sometimes
}
ffmpeg_options = {
'options': '-vn'
}
ytdl = youtube_dl.YoutubeDL(ytdl_format_options)
class YTDLSource(commands.Cog):
def __init__(self, source, *, data, volume=0.5):
super().__init__(source, volume)
self.data = data
self.title = data.get('title')
self.url = ""
@classmethod
async def from_url(cls, url, *, loop=None, stream=False):
loop = loop or asyncio.get_event_loop()
data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=not stream))
if 'entries' in data:
# take first item from a playlist
data = data['entries'][0]
filename = data['title'] if stream else ytdl.prepare_filename(data)
return filename
@bot.command(name = 'play')
async def play(self,ctx, url):
if not ctx.message.author.name == "Rohan Krishna":
await ctx.send('NOT AUTHORISED!')
return
try:
server = ctx.message.guild
voice_channel = server.voice_client
async with ctx.typing():
filename = await YTDLSource.from_url(url, loop=bot.loop)
voice_channel.play(discord.FFmpegPCMAudio(executable="ffmpeg.exe", source=filename))
await ctx.send('**Now playing:** {}'.format(filename))
except:
await ctx.send("The bot is not connected to a voice channel.")
@bot.command(name = 'join')
async def join(self,ctx):
if not ctx.message.author.voice:
await ctx.send("{} is not connected to a voice channel".format(ctx.message.author.name))
return
else:
channel = ctx.message.author.voice.channel
await channel.connect()
@bot.command(name='pause')
async def pause(self,ctx):
voice_client = ctx.message.guild.voice_client
if voice_client.is_playing():
await voice_client.pause()
else:
await ctx.send("The bot is not playing anything at the moment.")
@bot.command(name='resume')
async def resume(self,ctx):
voice_client = ctx.message.guild.voice_client
if voice_client.is_paused():
await voice_client.resume()
else:
await ctx.send("The bot was not playing anything before this. Use play_song command")
@bot.command(name='leave')
async def leave(self,ctx):
voice_client = ctx.message.guild.voice_client
if voice_client.is_connected():
await voice_client.disconnect()
else:
await ctx.send("The bot is not connected to a voice channel.")
@bot.command(name='stop')
async def stop(self,ctx):
voice_client = ctx.message.guild.voice_client
if voice_client.is_playing():
await voice_client.stop()
else:
await ctx.send("The bot is not playing anything at the moment.")
def setup(bot):
bot.add_cog(mod(bot=bot))
Такая проблема discord.ext.commands.errors.CommandNotFound: Command "join" is not found
. Команды не видит от play. я думаю проблема в двух классах и табуляции. Помогите новичку пожалуйста.)))