diff --git a/nessa/nessa.py b/nessa/nessa.py index 33969bb..9999852 100644 --- a/nessa/nessa.py +++ b/nessa/nessa.py @@ -22,6 +22,10 @@ class Nessa(discord.Client): self.tree.add_command(NessaTracker()) self.tree.copy_global_to(guild=discord.Object(id=GUILD_ID)) await self.tree.sync(guild=discord.Object(id=GUILD_ID)) + + def is_owner_or_admin(interaction: discord.Interaction): + """Check if the user is the bot owner or an administrator in the guild.""" + return interaction.user.id == OWNER_ID or interaction.user.guild_permissions.administrator @self.tree.command(name="shutdown", description="Shut down Nessa", guild=discord.Object(id=GUILD_ID)) async def shutdown(interaction: discord.Interaction): @@ -47,6 +51,18 @@ class Nessa(discord.Client): # Respond to the user to confirm the message has been sent await interaction.response.send_message("I've passed on your issue to the Chief!", ephemeral=True) + @self.tree.command(name="sync_commands", description="Force sync commands in a specific guild.") + @self.app_commands.check(is_owner_or_admin) # or @discord.app_commands.checks.is_owner() + async def sync_commands(interaction: discord.Interaction, guild_id: int): + if interaction.user.id == OWNER_ID: + guild = self.get_guild(guild_id) + if guild is None: + await interaction.response.send_message("Guild not found.", ephemeral=True) + return + await self.tree.sync(guild=discord.Object(id=guild)) + self.tree.copy_global_to(guild=discord.Object(id=guild)) + await interaction.response.send_message(f"Commands synced successfully for guild {guild.name}.", ephemeral=True) + async def on_ready(self): print(f"Logged on as {self.user}!") self.tree.copy_global_to(guild=discord.Object(id=GUILD_ID))