-1

I have simple music bot but it says this:"RuntimeWarning: coroutine 'BotBase.load_extension' was never awaited bot.load_extension('dismusic') RuntimeWarning: Enable tracemalloc to get the object allocation traceback"

" RuntimeWarning: coroutine 'BotBase.load_extension' was never awaited bot.load_extension('dch') RuntimeWarning: Enable tracemalloc to get the object allocation traceback "

Code:

import discord
from discord.ext import commands
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix='>', intents=intents)

bot.lava_nodes = [
    {
        'host': 'lava.link',
        'port': 80,
        'rest_uri': f'http://lava.link:80',
        'indetifier': 'MAIN',
        'password': 'anything',
        'region': 'singapore'
    }
]

@bot.event
async def on_ready():
    print('Bot is ready')
    bot.load_extension('dismusic')
    bot.load_extension('dch')
    
    
bot.run("OTg5OTI5Mjkxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");

  • It seems you're using `discord.py 2.0.0`, load_extension is a coroutine, more about load_extension in [the doc](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Bot.load_extension). You just need to put the `await` keyword before calling the method. `await bot.load_extension('cog')` – Paul Aug 24 '22 at 09:11
  • Does this answer your question? ["RuntimeWarning: coroutine 'BotBase.load\_extension' was never awaited" after updating discord.py](https://stackoverflow.com/questions/71504627/runtimewarning-coroutine-botbase-load-extension-was-never-awaited-after-upd) – TheFungusAmongUs Aug 24 '22 at 12:10
  • Don't load extensions in `on_ready` because it gets called multiple times. Instead, make a setup function that you run before starting the client. – Eric Jin Aug 25 '22 at 01:46

1 Answers1

1

You just need to replace bot.load_extension with await bot.load_extension - you haven’t awaited a function. Otherwise, your code looks fine. (By the way, discord is moving away from text based commands, you might want to look into slash commands)

Jaffa
  • 189
  • 1
  • 6