From e963c5ca8658ee09cf55b9260f388f9a91e10e90 Mon Sep 17 00:00:00 2001 From: Sweetbread Date: Thu, 18 May 2023 22:54:43 +0300 Subject: [PATCH] [feat]: Commands to group --- cogs/economic.py | 14 ++++++++------ cogs/music.py | 7 ++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cogs/economic.py b/cogs/economic.py index 708a5e9..2213d7f 100644 --- a/cogs/economic.py +++ b/cogs/economic.py @@ -53,7 +53,7 @@ class Economic(commands.Cog, name="Экономика"): async def on_message(self, message): if not message.author.bot and message.guild is not None and not message.content.startswith(tuple(await self.bot.command_prefix(self.bot, message))): data = await db.members.find_one({"id": message.author.id}) - flood_channels = await db.guild_settings.find_one({"id": message.guild.id}) + flood_channels = await db.guild_settings.find_one({"id": message.guild.id, 'type': 'general'}) if flood_channels is None: flood_channels = [] else: @@ -243,7 +243,10 @@ class Economic(commands.Cog, name="Экономика"): }) logger.debug(m["guild_stat"][str(guild.id)]["exp"]) - @app_commands.command(description="View balance and level") + + stat_gr = app_commands.Group(name="statistic", description="Some statistic") + + @stat_gr.command(description="View balance and level") async def rank(self, inter: discord.Interaction, user: discord.Member = None): if user is None: user = inter.user @@ -325,7 +328,7 @@ class Economic(commands.Cog, name="Экономика"): color=color) await inter.response.send_message(embed=e) - @app_commands.command(description="Top members of the guild") + @stat_gr.command(description="Top members of the guild") @app_commands.describe(category='Category') @app_commands.choices(category=[ Choice(name='Balance', value="Баланс"), @@ -401,7 +404,7 @@ class Economic(commands.Cog, name="Экономика"): await inter.response.send_message(embed=e) - @app_commands.command(description="Comparison of exp with other members") + @stat_gr.command(description="Comparison of exp with other members") @app_commands.choices(period=[ Choice(name='Per the entire period', value=-1), Choice(name='Per month', value=24*30), @@ -477,8 +480,7 @@ class Economic(commands.Cog, name="Экономика"): await inter.response.send_message(file=discord.File(f)) remove(f'tmp/{inter.id}.png') - - @app_commands.command() + @stat_gr.command() @app_commands.choices(period=[ Choice(name='Per the entire period', value=-1), Choice(name='Per month', value=24*30), diff --git a/cogs/music.py b/cogs/music.py index 6c6b5e4..6aaa1fa 100644 --- a/cogs/music.py +++ b/cogs/music.py @@ -6,7 +6,6 @@ import asyncio from loguru import logger from json import dumps from discord import app_commands -from discord.ext import commands from dataclasses import dataclass from bot import db @@ -31,8 +30,10 @@ class Channel: # skip_policy: Enum "everyone" -class Music(commands.Cog, name="Музыка"): +@app_commands.guild_only() +class Music(app_commands.Group, name="music"): def __init__(self, bot): + super().__init__() self.bot = bot self.queue: dict[int, Channel] = {} @@ -167,4 +168,4 @@ class Music(commands.Cog, name="Музыка"): async def setup(bot): - await bot.add_cog(Music(bot)) + bot.tree.add_command(Music(bot))