From b82d1bbf86425b4ac734d70857f4cfca2c707811 Mon Sep 17 00:00:00 2001 From: voXrey <72698969+voXrey@users.noreply.github.com> Date: Sun, 2 Jun 2024 14:17:48 +0200 Subject: [PATCH] Fix admin check --- cogs/admin.py | 11 ++++++----- main.py | 8 ++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cogs/admin.py b/cogs/admin.py index 7cb8c19..b36f7dc 100644 --- a/cogs/admin.py +++ b/cogs/admin.py @@ -1,7 +1,8 @@ import discord -from discord import app_commands +from discord import app_commands, Interaction from discord.app_commands import Choice from discord.ext import commands +from typing import cast from classes.my_cog import MyCog @@ -11,6 +12,10 @@ class CogGroup(app_commands.Group, name="cog", description="Gérer les cogs"): super().__init__() self.bot = bot + async def interaction_check(self, interaction: Interaction, /) -> bool: + team = cast(discord.Team, self.bot.application.team) + return any(interaction.user.id == team_member.id for team_member in team.members) + @app_commands.command(name="load") async def cog_load(self, interaction: discord.Interaction, extension: str): """ @@ -111,10 +116,6 @@ class Admin(MyCog): # Add cogs commands group to cog self.bot.tree.add_command(CogGroup(self.bot)) - async def cog_check(self, ctx): - admins = self.bot.owner_ids - return ctx.author.id in admins - async def setup(bot): await bot.add_cog(Admin(bot)) diff --git a/main.py b/main.py index dbb075f..8177789 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,8 @@ -from typing import Optional, List from os import getenv, listdir import re import discord +from typing import cast from discord import app_commands from discord.app_commands import Choice from discord.ext import commands @@ -23,7 +23,7 @@ class MyClient(commands.Bot): self.initial_extensions = ["cogs." + f[:-3] for f in listdir("./cogs") if f.endswith(".py") and f.__str__() != "__init__.py"] - #self.add_listener(self.on_message) + # self.add_listener(self.on_message) async def setup_hook(self): # cogs @@ -35,8 +35,11 @@ class MyClient(commands.Bot): await self.tree.sync(guild=guild) async def on_ready(self): + team = cast(discord.Team, self.application.team) + print(f'Logged in as {self.user} (ID: {self.user.id})') print(f"Discord version : {discord.__version__}") + print(f"Admins : {', '.join([m.name for m in team.members])}") print('------') async def on_message(self, msg): @@ -45,6 +48,7 @@ class MyClient(commands.Bot): if p.search(msg.content) is not None: await msg.reply("Quoicoubeh !") + if __name__ == "__main__": client = MyClient() client.run(getenv("TOKEN"))