Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow group creation outside of cogs #4

Closed
Slluxx opened this issue Nov 28, 2023 · 5 comments
Closed

Allow group creation outside of cogs #4

Slluxx opened this issue Nov 28, 2023 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@Slluxx
Copy link

Slluxx commented Nov 28, 2023

Currently it seems like a cog must create a group for other cogs to be able to join it. This only works if you have an always loaded (at least in the beginning) cog that spawns the group. This is counterproductive as cogs are meant to by dynamically loaded and unloaded.

Something like this should go around that issue but it does not work.

import discord
from discord.commands import SlashCommandGroup
from pycord.multicog import Bot

bot = Bot()

SlashCommandGroup("owner")
bot.load_extension("cogs.testcog")

bot.run("")
import discord
from discord.ext import commands
from pycord.multicog import add_to_group

class Testcog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @add_to_group("owner")
    @commands.slash_command()
    async def test(self, ctx):
        await ctx.respond("ok")

def setup(bot):
    bot.add_cog(Testcog(bot))
raise RuntimeError(f"no slash command group named {group_name} found.")
RuntimeError: no slash command group named owner found.
@Dorukyum
Copy link
Owner

I understand the issue but this is intended, you must define the group before adding any commands to it. Otherwise, the library would have to replace all missing and unloaded groups with placeholders, which is unnecessarily complex and would create confusion.

@Slluxx
Copy link
Author

Slluxx commented Nov 30, 2023

you must define the group before adding any commands to it

I am not sure if we are on the same page or if i am missing things that work behind the curtain, but as per my example above, i want to create the group before loading any extensions. SlashCommandGroup is executed to create a group before load_extension loads the cog and adds itself to that group.

The problem is that currently, i am forced to always load the cog that creates the group. If i change the load order or want to remove it, there is no group anymore and the rest of the cogs will fail to load too, which completly defeats the purpose of having dynamic loadable cogs/extensions.

You could seperate group creation and adding to a group like in my example above or even put both into the same decorator, which then checks if that group exists and creates it if not. Something like @create_or_add_to_group("mygroup") (the name chosen is just for demonstration purposes)

@Dorukyum
Copy link
Owner

Dorukyum commented Dec 7, 2023

What you're asking for requires an overhaul of the storage and loading systems for cogs and commands. I will try my best to write a clean implementation. Don't expect it too soon though.

@Dorukyum Dorukyum added the enhancement New feature or request label Dec 7, 2023
@Dorukyum Dorukyum self-assigned this Dec 7, 2023
@Dorukyum
Copy link
Owner

Dorukyum commented Jan 1, 2024

Update: I now have a working implementation, waiting on Pycord-Development/pycord#2299. The next release of pycord-multicog will be v2.0 and it will introduce breaking changes.

@Dorukyum
Copy link
Owner

Dorukyum commented Mar 5, 2024

@Slluxx Hey, I've just released pycord-multicog v2.0.0 with this feature implemented in c733fb6!

@Dorukyum Dorukyum closed this as completed Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants