2025-09-14 18:54:56 -04:00
|
|
|
import discord
|
|
|
|
|
from discord import app_commands
|
|
|
|
|
from discord.ext import commands
|
|
|
|
|
from discord.ext.commands import Context
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Sync(commands.Cog, name="sync"):
|
|
|
|
|
def __init__(self, bot) -> None:
|
|
|
|
|
self.bot = bot
|
|
|
|
|
|
2025-11-02 23:32:52 -05:00
|
|
|
async def send_embed(
|
|
|
|
|
self, context: Context, embed: discord.Embed, *, ephemeral: bool = False
|
|
|
|
|
) -> None:
|
2025-09-16 10:21:36 -04:00
|
|
|
interaction = getattr(context, "interaction", None)
|
|
|
|
|
if interaction is not None:
|
|
|
|
|
if interaction.response.is_done():
|
|
|
|
|
await interaction.followup.send(embed=embed, ephemeral=ephemeral)
|
|
|
|
|
else:
|
2025-11-02 23:32:52 -05:00
|
|
|
await interaction.response.send_message(
|
|
|
|
|
embed=embed, ephemeral=ephemeral
|
|
|
|
|
)
|
2025-09-16 10:21:36 -04:00
|
|
|
else:
|
|
|
|
|
await context.send(embed=embed)
|
|
|
|
|
|
2025-09-22 10:22:06 -04:00
|
|
|
@commands.hybrid_command(
|
2025-09-14 18:54:56 -04:00
|
|
|
name="sync",
|
|
|
|
|
description="Synchonizes the slash commands.",
|
|
|
|
|
)
|
2025-09-22 10:22:06 -04:00
|
|
|
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
|
|
|
|
|
@app_commands.allowed_installs(guilds=True, users=True)
|
2025-09-14 18:54:56 -04:00
|
|
|
@app_commands.describe(scope="The scope of the sync. Can be `global` or `guild`")
|
|
|
|
|
@commands.is_owner()
|
|
|
|
|
async def sync(self, context: Context, scope: str) -> None:
|
|
|
|
|
"""
|
|
|
|
|
Synchonizes the slash commands.
|
|
|
|
|
|
|
|
|
|
:param context: The command context.
|
|
|
|
|
:param scope: The scope of the sync. Can be `global` or `guild`.
|
|
|
|
|
"""
|
|
|
|
|
if scope == "global":
|
|
|
|
|
await context.bot.tree.sync()
|
|
|
|
|
embed = discord.Embed(
|
2025-09-16 10:21:36 -04:00
|
|
|
title="Sync",
|
2025-09-14 18:54:56 -04:00
|
|
|
description="Slash commands have been globally synchronized.",
|
2025-09-16 10:21:36 -04:00
|
|
|
color=0x7289DA,
|
2025-09-14 18:54:56 -04:00
|
|
|
)
|
2025-11-02 23:32:52 -05:00
|
|
|
embed.set_author(
|
|
|
|
|
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
|
|
|
|
|
)
|
2025-09-16 10:21:36 -04:00
|
|
|
await self.send_embed(context, embed)
|
2025-09-14 18:54:56 -04:00
|
|
|
return
|
|
|
|
|
elif scope == "guild":
|
|
|
|
|
context.bot.tree.copy_global_to(guild=context.guild)
|
|
|
|
|
await context.bot.tree.sync(guild=context.guild)
|
|
|
|
|
embed = discord.Embed(
|
2025-09-16 10:21:36 -04:00
|
|
|
title="Sync",
|
2025-09-14 18:54:56 -04:00
|
|
|
description="Slash commands have been synchronized in this guild.",
|
2025-09-16 10:21:36 -04:00
|
|
|
color=0x7289DA,
|
2025-09-14 18:54:56 -04:00
|
|
|
)
|
2025-11-02 23:32:52 -05:00
|
|
|
embed.set_author(
|
|
|
|
|
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
|
|
|
|
|
)
|
2025-09-16 10:21:36 -04:00
|
|
|
await self.send_embed(context, embed)
|
2025-09-14 18:54:56 -04:00
|
|
|
return
|
|
|
|
|
embed = discord.Embed(
|
2025-09-16 10:21:36 -04:00
|
|
|
title="Error",
|
|
|
|
|
description="The scope must be `global` or `guild`.",
|
|
|
|
|
color=0xE02B2B,
|
2025-09-14 18:54:56 -04:00
|
|
|
)
|
2025-11-02 23:32:52 -05:00
|
|
|
embed.set_author(
|
|
|
|
|
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
|
|
|
|
|
)
|
2025-09-16 10:21:36 -04:00
|
|
|
await self.send_embed(context, embed, ephemeral=True)
|
2025-09-14 18:54:56 -04:00
|
|
|
|
2025-09-22 10:22:06 -04:00
|
|
|
@commands.hybrid_command(
|
2025-09-14 18:54:56 -04:00
|
|
|
name="unsync",
|
|
|
|
|
description="Unsynchonizes the slash commands.",
|
|
|
|
|
)
|
2025-09-22 10:22:06 -04:00
|
|
|
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
|
|
|
|
|
@app_commands.allowed_installs(guilds=True, users=True)
|
2025-09-14 18:54:56 -04:00
|
|
|
@app_commands.describe(
|
|
|
|
|
scope="The scope of the sync. Can be `global`, `current_guild` or `guild`"
|
|
|
|
|
)
|
|
|
|
|
@commands.is_owner()
|
|
|
|
|
async def unsync(self, context: Context, scope: str) -> None:
|
|
|
|
|
"""
|
|
|
|
|
Unsynchonizes the slash commands.
|
|
|
|
|
|
|
|
|
|
:param context: The command context.
|
|
|
|
|
:param scope: The scope of the sync. Can be `global`, `current_guild` or `guild`.
|
|
|
|
|
"""
|
|
|
|
|
if scope == "global":
|
|
|
|
|
context.bot.tree.clear_commands(guild=None)
|
|
|
|
|
await context.bot.tree.sync()
|
|
|
|
|
embed = discord.Embed(
|
2025-09-16 10:21:36 -04:00
|
|
|
title="Unsync",
|
2025-09-14 18:54:56 -04:00
|
|
|
description="Slash commands have been globally unsynchronized.",
|
2025-09-16 10:21:36 -04:00
|
|
|
color=0x7289DA,
|
2025-09-14 18:54:56 -04:00
|
|
|
)
|
2025-11-02 23:32:52 -05:00
|
|
|
embed.set_author(
|
|
|
|
|
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
|
|
|
|
|
)
|
2025-09-16 10:21:36 -04:00
|
|
|
await self.send_embed(context, embed)
|
2025-09-14 18:54:56 -04:00
|
|
|
return
|
|
|
|
|
elif scope == "guild":
|
|
|
|
|
context.bot.tree.clear_commands(guild=context.guild)
|
|
|
|
|
await context.bot.tree.sync(guild=context.guild)
|
|
|
|
|
embed = discord.Embed(
|
2025-09-16 10:21:36 -04:00
|
|
|
title="Unsync",
|
2025-09-14 18:54:56 -04:00
|
|
|
description="Slash commands have been unsynchronized in this guild.",
|
2025-09-16 10:21:36 -04:00
|
|
|
color=0x7289DA,
|
2025-09-14 18:54:56 -04:00
|
|
|
)
|
2025-11-02 23:32:52 -05:00
|
|
|
embed.set_author(
|
|
|
|
|
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
|
|
|
|
|
)
|
2025-09-16 10:21:36 -04:00
|
|
|
await self.send_embed(context, embed)
|
2025-09-14 18:54:56 -04:00
|
|
|
return
|
|
|
|
|
embed = discord.Embed(
|
2025-09-16 10:21:36 -04:00
|
|
|
title="Error",
|
|
|
|
|
description="The scope must be `global` or `guild`.",
|
|
|
|
|
color=0xE02B2B,
|
2025-09-14 18:54:56 -04:00
|
|
|
)
|
2025-11-02 23:32:52 -05:00
|
|
|
embed.set_author(
|
|
|
|
|
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
|
|
|
|
|
)
|
2025-09-16 10:21:36 -04:00
|
|
|
await self.send_embed(context, embed, ephemeral=True)
|
|
|
|
|
|
|
|
|
|
async def cog_command_error(self, context: Context, error) -> None:
|
|
|
|
|
if isinstance(error, commands.NotOwner):
|
|
|
|
|
embed = discord.Embed(
|
|
|
|
|
title="Permission Denied",
|
|
|
|
|
description="You are not the owner of this bot!",
|
|
|
|
|
color=0xE02B2B,
|
|
|
|
|
)
|
2025-11-02 23:32:52 -05:00
|
|
|
embed.set_author(
|
|
|
|
|
name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp"
|
|
|
|
|
)
|
2025-09-16 10:21:36 -04:00
|
|
|
await self.send_embed(context, embed, ephemeral=True)
|
|
|
|
|
else:
|
|
|
|
|
raise error
|
2025-09-14 18:54:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
async def setup(bot) -> None:
|
|
|
|
|
await bot.add_cog(Sync(bot))
|