0
/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))
  • You need to add an await line. Check this one out. https://stackoverflow.com/questions/71504627/runtimewarning-coroutine-botbase-load-extension-was-never-awaited-after-upd – Chau T. Oct 25 '22 at 08:13

1 Answers1

0

You need to await in your last line, which is also mentioned in the error message.

So, change this

def setup(client):
  client.add_cog(music(client))

to this

def setup(client):
  await client.add_cog(music(client))

But both of these are just warnings, so you should be able to ignore them but they could lead to problems later on.
Regarding the tracemalloc, you can enable it to trace what memory the object allocates. (HOW)

  • i did change the code but theres a new error `Traceback (most recent call last): File "main.py", line 3, in import music File "/home/runner/AdequateEmbarrassedAmoeba/music.py", line 51 await client.add_cog(music(client)) ^ SyntaxError: 'await' outside async function` – High_Bread Oct 25 '22 at 08:35
  • Oh sorry, of course the setup function needs to be async then. So, `async def setup(client)` – Marc Leibold Oct 25 '22 at 09:42
  • alright the error's gone but a new thing has come up, the commands arent being 'found' `2022-10-25 10:11:29 ERROR discord.ext.commands.bot Ignoring exception in command None discord.ext.commands.errors.CommandNotFound: Command "join" is not found 2022-10-25 10:11:31 ERROR discord.ext.commands.bot Ignoring exception in command None discord.ext.commands.errors.CommandNotFound: Command "play" is not found` – High_Bread Oct 25 '22 at 10:09
  • You seem to have you function decorators wrong. Check out this article: https://betterprogramming.pub/how-to-make-discord-bot-commands-in-python-2cae39cbfd55 – Marc Leibold Oct 25 '22 at 19:01
  • apparently you need to initialize the bot first and the add `@bot.command()` as function decorator – Marc Leibold Oct 25 '22 at 19:02
  • https://mystb.in/PunkLeedsCompiled heres the main and music files ,so i have to initialize the bot and change function decorator? – High_Bread Oct 26 '22 at 07:43
  • yes exactly. And also change your discord token, if that is your real one – Marc Leibold Oct 26 '22 at 19:23
  • if this answered your question, please also mark it as an answer – Marc Leibold Oct 27 '22 at 14:31