Fix admin check
This commit is contained in:
parent
dfe9d3da74
commit
b82d1bbf86
|
@ -1,7 +1,8 @@
|
||||||
import discord
|
import discord
|
||||||
from discord import app_commands
|
from discord import app_commands, Interaction
|
||||||
from discord.app_commands import Choice
|
from discord.app_commands import Choice
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
from typing import cast
|
||||||
|
|
||||||
from classes.my_cog import MyCog
|
from classes.my_cog import MyCog
|
||||||
|
|
||||||
|
@ -11,6 +12,10 @@ class CogGroup(app_commands.Group, name="cog", description="Gérer les cogs"):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.bot = bot
|
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")
|
@app_commands.command(name="load")
|
||||||
async def cog_load(self, interaction: discord.Interaction, extension: str):
|
async def cog_load(self, interaction: discord.Interaction, extension: str):
|
||||||
"""
|
"""
|
||||||
|
@ -111,10 +116,6 @@ class Admin(MyCog):
|
||||||
# Add cogs commands group to cog
|
# Add cogs commands group to cog
|
||||||
self.bot.tree.add_command(CogGroup(self.bot))
|
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):
|
async def setup(bot):
|
||||||
await bot.add_cog(Admin(bot))
|
await bot.add_cog(Admin(bot))
|
||||||
|
|
8
main.py
8
main.py
|
@ -1,8 +1,8 @@
|
||||||
from typing import Optional, List
|
|
||||||
from os import getenv, listdir
|
from os import getenv, listdir
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
from typing import cast
|
||||||
from discord import app_commands
|
from discord import app_commands
|
||||||
from discord.app_commands import Choice
|
from discord.app_commands import Choice
|
||||||
from discord.ext import commands
|
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
|
self.initial_extensions = ["cogs." + f[:-3] for f in listdir("./cogs") if
|
||||||
f.endswith(".py") and f.__str__() != "__init__.py"]
|
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):
|
async def setup_hook(self):
|
||||||
# cogs
|
# cogs
|
||||||
|
@ -35,8 +35,11 @@ class MyClient(commands.Bot):
|
||||||
await self.tree.sync(guild=guild)
|
await self.tree.sync(guild=guild)
|
||||||
|
|
||||||
async def on_ready(self):
|
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'Logged in as {self.user} (ID: {self.user.id})')
|
||||||
print(f"Discord version : {discord.__version__}")
|
print(f"Discord version : {discord.__version__}")
|
||||||
|
print(f"Admins : {', '.join([m.name for m in team.members])}")
|
||||||
print('------')
|
print('------')
|
||||||
|
|
||||||
async def on_message(self, msg):
|
async def on_message(self, msg):
|
||||||
|
@ -45,6 +48,7 @@ class MyClient(commands.Bot):
|
||||||
if p.search(msg.content) is not None:
|
if p.search(msg.content) is not None:
|
||||||
await msg.reply("Quoicoubeh !")
|
await msg.reply("Quoicoubeh !")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
client = MyClient()
|
client = MyClient()
|
||||||
client.run(getenv("TOKEN"))
|
client.run(getenv("TOKEN"))
|
||||||
|
|
Loading…
Reference in New Issue