update/only allow admin to use commands
This commit is contained in:
2 files changed
+14
-5
No files matched your search
+12
-3
@@ -2,22 +2,31 @@
|
||||
from discord.ext import commands
|
||||
from discord import app_commands
|
||||
from discord import Interaction
|
||||
from discord import Member
|
||||
|
||||
class Event(app_commands.Group):
|
||||
def __init__(self, bot: commands.Bot, name: str, description: str):
|
||||
super().__init__(name=name, description=description)
|
||||
self.bot = bot
|
||||
|
||||
def hasPermission(self, user: Member) -> bool:
|
||||
for role in user.roles:
|
||||
if role.id == self.bot.config.ADMIN:
|
||||
return True
|
||||
return False
|
||||
|
||||
@app_commands.command(name="start", description="Start an event leaderboard")
|
||||
async def start(self, interaction: Interaction) -> None:
|
||||
if not self.hasPermission(interaction.user): await interaction.response.send_message("You don't have permission to use this command.", ephemeral=True)
|
||||
if self.bot._running: await interaction.response.send_message("Event already started")
|
||||
self.bot.scrape_file.start()
|
||||
self.bot._running = True
|
||||
await interaction.response.send_message("Starting new event leaderboard...")
|
||||
await interaction.response.send_message("Starting new event leaderboard...", ephemeral=True)
|
||||
|
||||
@app_commands.command(name="stop", description="Stop an event leaderboard")
|
||||
async def stop(self, interaction: Interaction) -> None:
|
||||
if not self.bot._running: await interaction.response.send_message("Event already stopped")
|
||||
if not self.hasPermission(interaction.user): await interaction.response.send_message("You don't have permission to use this command.", ephemeral=True)
|
||||
if not self.bot._running: await interaction.response.send_message("Event already stopped", ephemeral=True)
|
||||
self.bot.scrape_file.stop()
|
||||
|
||||
# Reset trackers
|
||||
@@ -28,7 +37,7 @@ class Event(app_commands.Group):
|
||||
self.bot.gamertags = []
|
||||
self.bot.message_id = ""
|
||||
|
||||
await interaction.response.send_message("Stopping event leaderboard...")
|
||||
await interaction.response.send_message("Stopping event leaderboard...", ephemeral=True)
|
||||
|
||||
async def setup(bot: commands.Bot) -> None:
|
||||
bot.tree.add_command(Event(bot, name="event", description="start or stop an event leaderboard"))
|
||||
Reference in new issue
Block a user