v2.4.1
load_extension problem
import os
import discord
import configparser
from discord.ext import commands
conf = configparser.ConfigParser()
conf.read('config.ini')
bot = commands.Bot(
command_prefix=commands.when_mentioned_or(conf.get('setting', 'Prefix')),
intents=discord.Intents.all()
)
for filename in os.listdir('module'):
if filename.endswith('.py'):
await bot.load_extension(f'module.{filename[:-3]}')
if __name__ == "__main__":
bot.run(conf.get('setting', 'TOKEN'))
import asyncio
import discord
from discord.ext import commands
from discord import ApplicationContext
from discord.commands import slash_command
class util(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_ready(self):
print(f'Logged in as {self.bot.user.name}')
@slash_command(description="ping")
async def ping(self, ctx: ApplicationContext):
await ctx.respond(f'Pong! In {round(self.bot.latency * 1000)}ms')
def setup(bot):
bot.add_cog(util(bot))
Error
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
bot.py:28: RuntimeWarning: coroutine 'BotBase.load_extension' was never awaited
bot.load_extension(f'module.{filename[:-3]}')
If add await and async with add_cog
Traceback (most recent call last):
File "/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/Users/lily199iu/.vscode/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/__main__.py", line 39, in <module>
cli.main()
File "/Users/lily199iu/.vscode/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 430, in main
run()
File "/Users/lily199iu/.vscode/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 284, in run_file
runpy.run_path(target, run_name="__main__")
File "/Users/lily199iu/.vscode/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 320, in run_path
code, fname = _get_code_from_file(run_name, path_name)
File "/Users/lily199iu/.vscode/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 294, in _get_code_from_file
code = compile(f.read(), fname, 'exec')
File "bot.py", line 26
await bot.load_extension('dismusic')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: 'await' outside function