discord.py icon indicating copy to clipboard operation
discord.py copied to clipboard

Make load_extention able to some options

Open sevenc-nanashi opened this issue 3 years ago • 4 comments

Summary

If load_extension has kwargs for setup command, it'll be so good

What is the feature request for?

discord.ext.commands

The Problem

Currently load_extension cannot pass options, so it's so hard to Config extensions. But if can pass some arguments for setup, it makes extension more customizable.

The Ideal Solution

bot.load_extension("myextension", option1="A")
def setup(bot, option1):
    bot.add_cog(MyCog(bot, option1))

The Current Solution

environment variable, add attribute to bot class?

Additional Context

I'm not native of English so this issue may be weird.

sevenc-nanashi avatar Aug 14 '21 09:08 sevenc-nanashi

See #5839.

SebbyLaw avatar Aug 14 '21 09:08 SebbyLaw

Then instead of arbitrary keyword arguments, a single optional data argument, that can be passed to the setup function if present. Would keep the signature clean.

nitori avatar Aug 21 '21 21:08 nitori

Then instead of arbitrary keyword arguments, a single optional data argument, that can be passed to the setup function if present. Would keep the signature clean.

Or pass the options as keyword-arguments. This would also allow just ignoring options you don't need in the current file.

E.g. in one extension file:

async def setup(bot: commands.Bot, *, my_option: int, **kwargs): ...

And in another file:

async def setup(bot: commands.Bot, **kwargs): ...

mwobat avatar Apr 23 '22 08:04 mwobat

Curious if here has been any progress on providing a canonical way to pass arguments and/or configuration from load_extension to the extensions setup call?

What would be the recommended way of doing so? Extending Bot?

DanielBaulig avatar Mar 30 '23 17:03 DanielBaulig