/home/runner/AdequateEmbarrassedAmoeba/music.py:48: RuntimeWarning: coroutine 'BotBase.add_cog' was never awaited
client.add_cog(music(client))
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
2022-10-24 12:01:22 INFO discord.client logging in using static token
2022-10-24 12:01:23 INFO discord.gateway Shard ID None has connected to Gateway (Session ID: 1b5daa4ed7ffc36b3a15e264a51cf46e).
I was making a discord bot to play music and found a yt tutorial showing how to make one, and followed it but two types of errors, one was a tracemalloc and the other was that i needed to await the function BotBase.add_cog, regarding the second error, idk where to await it
import discord
from discord.ext import commands
import youtube_dl
class music(commands.Cog):
def __init__(self,client):
self.client= client
@commands.command()
async def join(self,ctx):
if ctx.author.voice is None:
await ctx.send("You need to join a voice channel!")
voice_channel = ctx.author.voice.channel
if ctx.voice_client is None:
await voice_channel.connect()
else:
await ctx.voice_client.move_to(voice_channel)
@commands.command()
async def stop(self,ctx):
await ctx.voice_client.disconnect()
@commands.command()
async def play(self,ctx,url):
ctx.voice_client.stop()
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
YDL_OPTIONS = {'format':"bestaudio"}
vc = ctx.voice_client
with youtube_dl.YoutubeDL(YDL_Options) as ydl:
info = ydl.extract_info(url, download=False)
url2 = info['formats'][0]['url']
source = await discord.FFmpegOpusAudio.from_probe(url2,
**FFMPEG_OPTIONS)
vc.play(source)
@commands.command()
async def pause(self,ctx):
await ctx.voice_client.pause()
await ctx.send("Paused")
@commands.command()
async def resume(self,ctx):
await ctx.voice_client.resume()
await ctx.send("Resumed")
def setup(client):
client.add_cog(music(client))