mirror of
https://github.com/neoarz/Syntrel.git
synced 2025-12-25 11:40:12 +01:00
style: new code layout
This commit is contained in:
94
cogs/owner/sync.py
Normal file
94
cogs/owner/sync.py
Normal file
@@ -0,0 +1,94 @@
|
||||
"""
|
||||
Copyright © Krypton 2019-Present - https://github.com/kkrypt0nn (https://krypton.ninja)
|
||||
Description:
|
||||
🐍 A simple template to start to code your own and personalized Discord bot in Python
|
||||
|
||||
Version: 6.4.0
|
||||
"""
|
||||
|
||||
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
|
||||
|
||||
@commands.command(
|
||||
name="sync",
|
||||
description="Synchonizes the slash commands.",
|
||||
)
|
||||
@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(
|
||||
description="Slash commands have been globally synchronized.",
|
||||
color=0xBEBEFE,
|
||||
)
|
||||
await context.send(embed=embed)
|
||||
return
|
||||
elif scope == "guild":
|
||||
context.bot.tree.copy_global_to(guild=context.guild)
|
||||
await context.bot.tree.sync(guild=context.guild)
|
||||
embed = discord.Embed(
|
||||
description="Slash commands have been synchronized in this guild.",
|
||||
color=0xBEBEFE,
|
||||
)
|
||||
await context.send(embed=embed)
|
||||
return
|
||||
embed = discord.Embed(
|
||||
description="The scope must be `global` or `guild`.", color=0xE02B2B
|
||||
)
|
||||
await context.send(embed=embed)
|
||||
|
||||
@commands.command(
|
||||
name="unsync",
|
||||
description="Unsynchonizes the slash commands.",
|
||||
)
|
||||
@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(
|
||||
description="Slash commands have been globally unsynchronized.",
|
||||
color=0xBEBEFE,
|
||||
)
|
||||
await context.send(embed=embed)
|
||||
return
|
||||
elif scope == "guild":
|
||||
context.bot.tree.clear_commands(guild=context.guild)
|
||||
await context.bot.tree.sync(guild=context.guild)
|
||||
embed = discord.Embed(
|
||||
description="Slash commands have been unsynchronized in this guild.",
|
||||
color=0xBEBEFE,
|
||||
)
|
||||
await context.send(embed=embed)
|
||||
return
|
||||
embed = discord.Embed(
|
||||
description="The scope must be `global` or `guild`.", color=0xE02B2B
|
||||
)
|
||||
await context.send(embed=embed)
|
||||
|
||||
|
||||
async def setup(bot) -> None:
|
||||
await bot.add_cog(Sync(bot))
|
||||
Reference in New Issue
Block a user