Переглянути джерело

Switching pc playing with modals

root 3 роки тому
батько
коміт
b84d37c64f
1 змінених файлів з 21 додано та 0 видалено
  1. 21 0
      bot/cogs/admin.py

+ 21 - 0
bot/cogs/admin.py

@@ -8,10 +8,31 @@ from common.logging import report
 from common.settings import check_ignore
 
 
+class ChannelSettingsModal(discord.ui.Modal):
+	def __init__(self, *args, **kwargs) -> None:
+		super().__init__(*args, **kwargs)
+
+		self.add_item(discord.ui.InputText(label="Interact"))
+		self.add_item(discord.ui.InputText(label="Games", style=discord.InputTextStyle.long))
+
+	async def callback(self, interaction: discord.Interaction):
+		print(f"interaction: {interaction}")
+		embed = discord.Embed(title="Test Modal Results")
+		embed.add_field(name="Interact", value=self.children[0].value)
+		embed.add_field(name="Games", value=self.children[1].value)
+		await interaction.response.send_message(embeds=[embed])
+
+
 class Admin(commands.Cog):
 	def __init__(self, bot): # Special method that is called when the cog is loaded
 		self.bot = bot
 
+	@commands.slash_command()
+	async def modal_slash(self, ctx: discord.ApplicationContext):
+		"""Shows an example of a modal dialog being invoked from a slash command."""
+		modal = ChannelSettingsModal(title="Adjust channel functions.")
+		await ctx.send_modal(modal)
+
 	@commands.slash_command(
 		description="Get the bot's current websocket and API latency.",
 		brief="Test latency",