import discord from discord import app_commands from discord.ext import commands from discord.ui import ChannelSelect #from common.logging import report from common.settings import check_ignore from query.guild import set_output_channel class View(discord.ui.View): def __init__(self, pg): super().__init__() self.pg = pg @discord.ui.select(cls=ChannelSelect, channel_types=[discord.ChannelType.text]) async def select_channels(self, interaction: discord.Interaction, select: ChannelSelect): await set_output_channel(self.pg, interaction.guild_id, select.values[0].id) return await interaction.response.send_message(f'You selected {select.values[0].mention}') class Select(discord.ui.Select): def __init__(self, pg, channels): self.pg = pg print(channels) options = [] for channel in channels: options.append(discord.SelectOption(label=str(channel.name),emoji="👌",description=str(channel.category)),) print(options) #options=[ # discord.SelectOption(label="Option 1",emoji="👌",description="This is option 1!"), # discord.SelectOption(label="Option 2",emoji="✨",description="This is option 2!"), # discord.SelectOption(label="Option 3",emoji="🎭",description="This is option 3!") # ] super().__init__(placeholder="Select an option",max_values=1,min_values=1,options=options) async def callback(self, interaction: discord.Interaction): await set_output_channel(self.pg, interaction.guild_id, 971796738484625468) await interaction.response.send_message(content=f"Your choice is {self.values[0]}!", ephemeral=True) class SelectView(discord.ui.View): def __init__(self, pg, channels, *, timeout = 180): super().__init__(timeout=timeout) self.add_item(Select(pg, channels)) class Admin(commands.Cog): """Administrative functionality.""" def __init__(self, bot: commands.Bot): self.bot = bot @app_commands.command( name="guildsettings", description="Modify guild specific settings", ) @commands.has_guild_permissions(administrator=True) async def guildsettings(self, interaction: discord.Interaction): # Halt on ignore list. if await check_ignore(self.bot.pg, interaction.user): return #await ctx.send("Menus!", view=SelectView(self.bot.pg, ctx.guild.channels)) await interaction.response.send_message("Menus!", view=View(self.bot.pg), ephemeral=True) @commands.command( name="sync", description="Sync commands", brief="Synchronise commands with Discord", help="Update the bot commands" ) @commands.is_owner() async def sync(self, ctx: commands.Context) -> None: synced = await ctx.bot.tree.sync() await ctx.send(f"Synced {len(synced)} commands globally") @commands.command( name="testsync", description="Sync commands", brief="Synchronise commands to this Discord", help="Update the bot commands" ) @commands.is_owner() async def testsync(self, ctx: commands.Context) -> None: 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 this guild", ephemeral=True) async def setup(bot: commands.Bot): await bot.add_cog(Admin(bot))