root 1 год назад
Родитель
Сommit
0143238913
2 измененных файлов с 51 добавлено и 34 удалено
  1. 44 28
      bot/commands/admin.py
  2. 7 6
      bot/commands/general.py

+ 44 - 28
bot/commands/admin.py

@@ -1,4 +1,5 @@
 from discord.ext import commands
+import discord
 
 async def setup(bot: commands.Bot):
 	await bot.add_cog(Admin(bot))
@@ -10,31 +11,46 @@ class Admin(commands.Cog):
 	def __init__(self, bot: commands.Bot):
 		self.bot = bot
 
-		@commands.command(
-			name="gsync",
-			description="Sync commands globally",
-			brief="Synchronise commands with all Discord guilds",
-			help="Update the bot commands for all Discord guilds"
-		)
-		async def gsync(self, ctx: commands.Context):
-			print(self.bot.tree.get_commands())
-			print(self.bot.tree.fetch_commands())
-			guild_count = 0
-			for guild in self.bot.guilds:
-				fmt = await ctx.bot.tree.sync(guild=guild)
-				guild_count += 1
-			await ctx.send(content=f"Synced tree of {len(fmt)} commands to {guild_count}/{len(self.bot.guilds)} guilds", ephemeral=True)
-
-		@commands.command(
-			name="sync",
-			description="Sync commands",
-			brief="Synchronise commands with Discord",
-			help="Update the bot commands"
-		)
-		async def sync(self, ctx: commands.Context):
-			print(self.bot.tree.get_commands())
-			print(self.bot.tree.fetch_commands())
-			ctx.bot.tree.copy_global_to(guild=ctx.guild)
-			synced = await ctx.bot.tree.sync(guild=ctx.guild)
-
-			await ctx.send(content=f"Synced {len(synced)} commands to the current guild", ephemeral=True)
+	@commands.command(
+		name="gsync",
+		description="Sync commands globally",
+		brief="Synchronise commands with all Discord guilds",
+		help="Update the bot commands for all Discord guilds"
+	)
+	async def gsync(self, ctx: commands.Context):
+		print(self.bot.tree.get_commands())
+		print(self.bot.tree.fetch_commands())
+		guild_count = 0
+		for guild in self.bot.guilds:
+			fmt = await ctx.bot.tree.sync(guild=guild)
+			guild_count += 1
+		await ctx.send(content=f"Synced tree of {len(fmt)} commands to {guild_count}/{len(self.bot.guilds)} guilds", ephemeral=True)
+
+	@commands.command(
+		name="sync",
+		description="Sync commands",
+		brief="Synchronise commands with Discord",
+		help="Update the bot commands"
+	)
+	async def sync(self, ctx: commands.Context):
+		print(self.bot.tree.get_commands())
+		print(self.bot.tree.fetch_commands())
+		ctx.bot.tree.copy_global_to(guild=ctx.guild)
+		synced = await ctx.bot.tree.sync(guild=ctx.guild)
+
+		await ctx.send(content=f"Synced {len(synced)} commands to the current guild", ephemeral=True)
+
+
+
+	@commands.command(
+		name="testsync",
+		description="Sync commands",
+		brief="Synchronise commands with Discord",
+		help="Update the bot commands"
+	)
+	async def testsync(self, ctx: commands.Context):
+		guild = discord.Object(id=962355492850638939)
+		ctx.bot.tree.copy_global_to(guild=guild)
+		synced = await ctx.bot.tree.sync(guild=guild)
+
+		await ctx.send(content=f"Synced {len(synced)} commands to the test guild", ephemeral=True)

+ 7 - 6
bot/commands/general.py

@@ -1,5 +1,7 @@
+import discord
 from discord.ext import commands
 import time
+from discord import app_commands
 
 
 async def setup(bot: commands.Bot):
@@ -12,14 +14,13 @@ class GeneralCommands(commands.Cog):
 	def __init__(self, bot: commands.Bot):
 		self.bot = bot
 
-	@commands.command(
+	@app_commands.command(
+		name="ping",
 		description="Get the bot's current websocket and API latency.",
-		brief="Test latency",
-		help="Test latency by polling the gateway and API."
 	)
-	async def ping(self, ctx: commands.Context):
+	async def ping(self, interaction: discord.Interaction) -> None:
 		start_time = time.time()
-		message = await ctx.send(f"Pong!\nGateway heartbeat in {round(self.bot.latency * 1000)}ms.")
+		#message = await ctx.send(f"Pong!\nGateway heartbeat in {round(self.bot.latency * 1000)}ms.")
 		end_time = time.time()
 
-		await ctx.send(f"API roundtrip latency {round((end_time - start_time) * 1000)}ms.")
+		await interaction.response.send_message(f"API roundtrip latency {round((end_time - start_time) * 1000)}ms.")