#๐Ÿ”’ Reusing Group Commands externally

10 messages ยท Page 1 of 1 (latest)

earnest vessel
#

Hi ๐Ÿ‘‹ Question, is it possible to use a command group variable in another file? I am trying to work on a backup sys and i'm trying to distribute code between different files so that is not one whole file with 1k lines of code, as of right now i'm trying to make /backup admin manage, i got to a point where it did show up but didn't work, it gave a signature mismatch type error.

Essentially using this group command

import discord
from discord.ext import commands
from discord import app_commands
import json
import os
import aiohttp
import requests
from io import BytesIO 
import asyncio
from PIL import Image, ImageDraw, ImageFont
from discord.ui import View, Button
import math
from typing import List 

BACKUPS_PER_PAGE = 5
admin_group = app_commands.Group(name="admin", description="Admin commands", parent=Backup.backup_group)


class Backup(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.backup_dir = 'data/backups'
        os.makedirs(self.backup_dir, exist_ok=True)

        self.backup_limits = {
            "max_backups": 5,
            "max_size_mb": 10
        }
    backup_group = app_commands.Group(name="backup", description="Manage server backups")```

in:

```py
import discord
from discord.ext import commands
from discord import app_commands
from backup_sys.Backup import Backup
import backup_sys.Backup


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

    @backup_sys.Backup.admin_group.command(name="manage", description="Manage admin backups")
    async def manage(self, interaction: discord.Interaction):
        await interaction.response.send_message("Managing backups...")```

Currently Its a bit messy been trying to move things from places and testing with it but no good results.

Thank you for your help and time. ๐Ÿ™
nova nexusBOT
#

@earnest vessel

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

dusty phoenix
earnest vessel
#

Well, I want to have it organized and like I said I don't want the backup.py to be like 1k lines of code, its already at 641. ๐Ÿฅถ ๐Ÿ˜…

dusty phoenix
#

if it's all related, it doesn't matter

#

some stdlib modules are several thousands of lines long but if they're all about the same thing, then whats the issue

earnest vessel
#

Well, I guess that makes sense. ๐Ÿ˜… Will do. Thanks for your time and help. ๐Ÿ™

nova nexusBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.