0

This is my Code for Music Command I get this error Mentioned Above Can anyone Help Me Out ?

class Music(commands.Cog):
    """Bot commands to help play music."""

    def __init__(self, bot, config):
        self.bot = bot
        self.config = config[__name__.split(".")[
            -1]]  # retrieve module name, find config entry
        self.states = {}
        self.bot.add_listener(self.on_reaction_add, "on_reaction_add")
  • 1
    Which command leads to the error, how do you instantiate the class instance? – Daniel Lenz Sep 26 '21 at 11:21
  • 3
    Your `Music` takes two arguments: (`bot` and `config`)... you used only one – Anwarvic Sep 26 '21 at 11:22
  • Seems like you haven't given a value to `config` when creating the object – Tharu Sep 26 '21 at 11:24
  • What Value will Config Hold @Old_Arrack – Hydra Sep 26 '21 at 11:24
  • When you created the `Music` class you also take config as a parameter, you might be able to avoid the error by giving it a value. – Tharu Sep 26 '21 at 11:27
  • If this is really your code and you don't know what this is for, you might want to try and remove the `config` argument from your `__init__` and remove this line: `self.config = config[__name__.split(".")[-1]] # retrieve module name, find config entry` from your code. – Almog-at-Nailo Sep 26 '21 at 11:31
  • Or just give the parameter a [default value](https://stackoverflow.com/questions/15535655/optional-arguments-in-initializer-of-python-class) – Tharu Sep 26 '21 at 11:35
  • If u are using __init__ then self also need to call as a argument position – Ehsan Rahi Sep 26 '21 at 13:32

1 Answers1

1

This likely happened because you did something like

a = Music(something)

And forgot to enter something for config. To solve this you could give config some default value so something like,

class Music(commands.Cog):

    def __init__(self, bot, config='some default thing'):
        self.bot = bot
        self.config = config[__name__.split(".")[
            -1]]  # retrieve module name, find config entry
        self.states = {}
        self.bot.add_listener(self.on_reaction_add, "on_reaction_add")

Or if config is required you could put something for config on the line that you called it, So using a = Music(something,something_else) instead of a = Music(something)