def __init__(self): self.arguments = [{ "prompt": "Would you like to **change** your log channels (add/delete), or **view** your " "current log channels?", "name": "choice", "type": "choice", "components": [ discord.ui.Select( max_values=1, options=[ discord.SelectOption( label="Change log channels", description="Add/delete a log channel."), discord.SelectOption( label="View log channels", description="View your log channels.") ]) ], "choices": ["change log channels", "add", "delete", "view log channels"] }] self.permissions = Bloxlink.Permissions().build("BLOXLINK_MANAGER") self.category = "Administration" self.aliases = ["logchannels", "log-channel", "log-channels"] self.slash_enabled = True
class SelectJoinModeView(text.PromptView): @discord.ui.select(options=[ discord.SelectOption( label="Public", value="Public", description="Everyone can join", emoji= "\U0001f468\U0000200d\U0001f468\U0000200d\U0001f467\U0000200d\U0001f467", ), discord.SelectOption( label="Request", value="Request", description="Everyone can ask to join & leaders can accept/deny", emoji="\U0001f4e9", ), discord.SelectOption( label="Private", value="Private", description="No one can join & moderation has to give role out", emoji="\U0001f575", ), ]) async def select(self, component, interaction): self.result = component.values[0] self.stop()
def gen_embeds(self): options, embeds = [], [] options.append( discord.SelectOption(label="Home", description="Show the home page.", emoji='👋')) embeds.append(self.home) for cog in self.get_cogs(): if "help_custom" in dir(cog): emoji, label, description = cog.help_custom() options.append( discord.SelectOption(label=label, description=description, emoji=emoji)) embed = discord.Embed( title=f"{emoji} Help · {label}", description=f"`{cog.__doc__}`", url="https://github.com/PaulMarisOUMary/Algosup-Discord") embed.set_footer( text= "Remind : Hooks such as <> must not be used when executing commands.", icon_url=self.ctx.message.author.display_avatar.url) for command in cog.get_commands(): params = "" for param in command.clean_params: params += f" <{param}>" embed.add_field(name=f"{command.name}{params}", value=f"{command.help}\n\u200b", inline=False) embeds.append(embed) return options, embeds
def __init__(self): self.permissions = Bloxlink.Permissions().build("BLOXLINK_MANAGER") self.category = "Administration" self.arguments = [{ "prompt": "Would you like to alter/disable the join messages for **verified** or **unverified** users?", "type": "choice", "components": [ discord.ui.Select( max_values=1, options=[ discord.SelectOption( label="Verified users", description="Change the message for verified users." ), discord.SelectOption( label="Unverified users", description= "Change the message for unverified users."), ]) ], "choices": ("Verified users", "Unverified users"), "name": "subcommand" }] self.hidden = True self.aliases = ["join-channel"]
def __init__(self, client: commands.Bot): super().__init__( custom_id="report_support_select", placeholder="Select what kind of Help you need", min_values=1, max_values=1, options=[ discord.SelectOption( label="Report", description="Report another user for breaking the rules.", emoji="<:politehammer:608941633454735360>"), discord.SelectOption( label="Support", description="I need help with the server in general.", emoji="<:slothconfused:738579956598046802>"), discord.SelectOption( label="Help", description="I need to change some roles and I can't.", emoji="<:irrelevant:673334940632481793>"), discord.SelectOption(label="Oopsie", description="Cancel, I missclicked.", emoji="❌"), ]) self.client = client self.cog = client.get_cog('ReportSupport')
def _get_options(self) -> List[discord.SelectOption]: """Returns a new instance of the option list so it doesn't get mixed up when editing""" return [ discord.SelectOption(label="rock", value="-1", emoji="\U0001f5ff"), discord.SelectOption(label="paper", value="0", emoji="\U0001f4c4"), discord.SelectOption(label="scissors", value="1", emoji="\U00002702") ]
def __init__(self, class_emojis): options = [] for emoji in class_emojis: options.append(discord.SelectOption(label=emoji.name, emoji=emoji)) options.append( discord.SelectOption(label=_("Remove"), value='remove', emoji="\u274C")) super().__init__(placeholder=_("Class"), options=options)
def __init__(self, the_class): super().__init__() self.the_class = the_class options = [ discord.SelectOption(label="General Question", description="Questions about the bot's functionality or pretty much anything", emoji="РЮЊ"), discord.SelectOption(label="Privacy Concerns", description="Concerns about your privacy, data removal requests.", emoji="<:privacy:733465503594708992>"), discord.SelectOption(label="Partnership Application", description="Partner a bot/server/organization with us.", emoji="<:p_:748833273383485440>"), discord.SelectOption(label="Bug Report", description="Report a potential bug you found using our bot.", emoji="ЪљЏ"), discord.SelectOption(label="Blacklist Appeal", description="Been blacklisted? Select this option to appeal your blacklist.", emoji="<:unban:687008899542286435>"), ] super().__init__(placeholder="Choose your ticket topic...", min_values=1, max_values=1, options=options, custom_id='dredd_support:ticket_dropdown')
def __init__(self): # Set the options that will be presented inside the dropdown options = [ discord.SelectOption(label='Red', description='Your favourite colour is red', emoji='🟥'), discord.SelectOption(label='Green', description='Your favourite colour is green', emoji='🟩'), discord.SelectOption(label='Blue', description='Your favourite colour is blue', emoji='🟦'), ] # The placeholder is what will be shown when no option is chosen # The min and max values indicate we can only pick one of the three options # The options parameter defines the dropdown options. We defined this above super().__init__(placeholder='Choose your favourite colour...', min_values=1, max_values=1, options=options)
async def on_ready(self) -> None: """ Makes all existing Role Selection menus in the database consistent on Discord. """ selection_menus = await self.get_selection_menus() messages = {} # Groups all selection options by message for select_option in selection_menus: try: if not messages.get(select_option[0]): messages[select_option[0]] = [select_option[3:]] else: messages[select_option[0]].append(select_option[3:]) except Exception as e: print('error in roleselection', e) # Makes all drop-downs for message_id, select_options in messages.items(): try: view = discord.ui.View(timeout=None) options = {} for select_option in select_options: index = select_option[3] if not options.get(index): options[index] = [ discord.SelectOption(label=select_option[0], emoji=select_option[1], value=str(select_option[2])) ] else: options[index].append( discord.SelectOption(label=select_option[0], emoji=select_option[1], value=str(select_option[2]))) for key, values in options.items(): select = RoleSelect(placeholder=key, custom_id=key.lower().replace( ' ', '_'), options=values) view.add_item(select) self.client.add_view(view=view, message_id=message_id) except Exception as e: print('ERROR IN RoleSelection', e) else: continue print('RoleSelection cog is online!')
async def read(self, ctx: commands.Context, *, title: str) -> None: """Initialise an instance of Bakerbot's manga reader.""" async with ctx.typing(): manga = await mangadex.Backend.manga(title) await manga.aggregate(language="en") await manga.feed(language="en") paginator = utilities.Paginator() paginator.placeholder = "Manga chapters: Options" available = [] for index, chapter in enumerate(manga.chapters): if chapter.volume is not None: available.append(f"Volume {chapter.volume}") if chapter.chapter is not None: available.append(f"Chapter {chapter.chapter}") description = ", ".join(available) or "No chapter/volume number available." label = utilities.Limits.limit(chapter.title or description, utilities.Limits.SELECT_LABEL) value = utilities.Limits.limit(description, utilities.Limits.SELECT_DESCRIPTION) option = discord.SelectOption(label=label, value=str(index), description=value) paginator.add(option) available.clear() message = await ctx.reply("Select a chapter to start reading.", view=paginator) if (choice := await paginator.wait()) is not None: reader = MangaReaderView(manga, int(choice)) await reader.run(message)
def create_option(room, index): m_description = room.english_name if room.current_quantity >= room.room_quant: m_description = "(MAX) " + m_description return discord.SelectOption(label=room.room_name.decode("utf-8"), value=index, description=m_description)
async def _wait_for_defense(self, ctx:commands.Context, other:User, effects:list) -> None: if len(effects) == 0: return effects = [Card(c) for c in effects] view = View(other.id, timeout=20) view.add_item(Select(options=[discord.SelectOption(label=c.name, emoji=c.emoji, value=str(c.id)) for c in effects])) view.add_item(Button(label="Ignore", style=discord.ButtonStyle.red)) msg = await ctx.send(f"<@{other.id}> {ctx.author} has used the spell `{self.id}` on you! You have {len(effects)} spells to defend yourself. You can either choose one of them to defend yourself with or let the attack go through", view=view) await view.wait() await view.disable(msg) if not view.value: if view.timed_out: await ctx.send(f"No response from the attacked user, the attack goes through!", reference=msg) else: await ctx.send("You decided not to use a defense spell, the attack goes through!", reference=msg) return if isinstance(view.value, int): other.remove_card(view.value) raise SuccessfullDefense(f"<@{other.id}> successfully defended against your attack") else: await ctx.send("You decided not to use a defense spell, the attack goes through!", reference=msg)
async def shop(self, ctx): if not ctx.invoked_subcommand: subcommands = [c for c in ctx.command.commands] view = View(ctx.author.id) view.add_item( Select(options=[ discord.SelectOption(label=f"{c.name} shop", value=str(i)) for i, c in enumerate(subcommands) ])) embed = discord.Embed.from_dict({ "title": "Shop menu", "description": "Select the shop you want to visit", "image": { "url": "https://cdn.discordapp.com/attachments/795448739258040341/885927080410361876/image0.png" }, "color": 0x1400ff }) msg = await ctx.send(embed=embed, view=view) await view.wait() await view.disable(msg) if view.value is None: return await msg.delete() await ctx.invoke( subcommands[int(view.value)] ) # calls a shop subcommand if a shop was specified
async def send_command_pages(self): opts_and_sources = {} for cog, infos in self.all_command_infos_by_category.items(): name = cog.qualified_name if cog else f"\u200b{self.no_category}" try: emoji, short_desc = cog.help_meta except AttributeError: emoji, short_desc = None, None opt = discord.SelectOption( label=name, emoji=emoji, description=short_desc ) if cog and cog.description: description = self.description + "\n\n" + cog.description else: description = self.description opts_and_sources[opt] = HelpCommandsMessageSource( description, infos ) paginator = views.SelectButtonPaginatorView( opts_and_sources, select_placeholder="\ud83d\udcda Select a category for commands" ) await paginator.start(self.context)
class SelectTagCreationView(text.PromptView): @discord.ui.select(options=[ discord.SelectOption( label="Everyone", value="Everyone", emoji= "\U0001f468\U0000200d\U0001f468\U0000200d\U0001f467\U0000200d\U0001f467", ), discord.SelectOption( label="Only Server Administrators", value="Administrators", emoji="\U0001f46e", ), ]) async def slct(self, select, interaction): self.result = select.values[0] self.stop()
async def choose(self, ctx): options = [ discord.SelectOption(label='Pineapple', value='Pineapple', description='The sweet tasting pineapple', emoji='ЪЇЇ', default=False), discord.SelectOption(label='Eggplant', value='Eggplant', description='Suspicious', emoji='ЪЇє', default=False), discord.SelectOption(label='Grapes', value='Grapes', description='Mhm, perfect for the summer', emoji='ЪЇЄ', default=False), discord.SelectOption(label='Apples', value='Apples', description='An apple a day keeps Jotte away', emoji='ЪЇј', default=False), discord.SelectOption(label='Banana', value='Banana', description='MMMM BAANAAAANAAA', emoji='ЪЇї', default=False) ] class View(discord.ui.View): def __init__(self): super().__init__(timeout=None) self.votes = {} @discord.ui.select(placeholder="Choose your favorite fruit", options=options) async def select(self, select, interaction): if interaction.user.name in (keys := list(self.votes.keys())): return await interaction.response.send_message( "You've already chosen.", ephemeral=True) self.votes[ interaction.user.name] = interaction.data['values'][0] em = discord.Embed(title=f"What is your favorite fruit?") for k, v in self.votes.items(): em.add_field(name=str(k), value=v) await interaction.message.edit(embed=em)
def __init__(self, categories, paginator): self.paginator = paginator options = [ discord.SelectOption(label=c, default = c == paginator.current_category) for c in categories ] super().__init__(placeholder=paginator.current_category, min_values=1, max_values=1, options=options)
def __init__(self, roblox_user): self.roblox_user = roblox_user options = [ discord.SelectOption(label=o) for o in ("Roblox Username", "Roblox ID", "Display Name", "Description", "Profile URL") ] super().__init__(placeholder="Get the text of...", options=options)
def __init__(self, *, options: list[Track]): options = [discord.SelectOption(label=f"{number+1}) {track.title}") for number, track in enumerate(options)] super().__init__( placeholder="Select the songs you want to play", options=options, min_values=1, max_values=1, disabled=False, )
def __init__(self, conn, raid_id): available = select(conn, 'Players', ['player_id, byname'], ['raid_id', 'unavailable'], [raid_id, False]) if len(available) > 25: available = available[:25] # discord API limit is 25 options options = [] for player in available: options.append( discord.SelectOption(value=player[0], label=player[1])) super().__init__(placeholder=_("Player"), options=options)
def __init__(self, cog, guilds): self.cog = cog options = [] for guild in guilds: name = f"{guild['name']} [{guild['tag']}]" options.append(discord.SelectOption(label=name, value=guild["id"])) super().__init__(options=options, placeholder="Select guilds", min_values=1, max_values=len(options))
def __init__(self): self.permissions = Bloxlink.Permissions().build("BLOXLINK_MANAGER") self.category = "Premium" self.arguments = [{ "prompt": "Magic Roles allow you to create roles that have special abilities within Bloxlink.\n\n" "Would you like to **add** a new magic role, **view** your existing magic roles, or " "**delete** an existing magic role?", "type": "choice", "components": [discord.ui.Select(max_values=1, options=[ discord.SelectOption(label="Add a new Magic Role"), discord.SelectOption(label="View Magic Roles"), discord.SelectOption(label="Delete a Magic Role"), ])], "choices": ("add a new magic role", "view magic roles", "delete a magic role"), "name": "subcommand" }] self.hidden = True self.aliases = ["magicrole", "magicroles", "magic-roles"] self.free_to_use = True
class RoleSubscription(ui.View): def __init__(self, bot: HelpCenterBot): super().__init__(timeout=None) self.bot = bot @ui.select(options=[discord.SelectOption(label=_('30 minutes'), value='1_800'), discord.SelectOption(label=_('1 heure'), value='3_600'), discord.SelectOption(label=_('3 heures'), value='10_800'), discord.SelectOption(label=_('12 heures'), value='43_200'), discord.SelectOption(label=_('1 journée'), value='86_400')]) async def give_role(self, select: ui.Select, inter: discord.Interaction): time = datetime.timedelta(seconds=int(select.values[0])) old_task = discord.utils.find(lambda task: task.get_name() == str(inter.user.id), asyncio.all_tasks(loop=self.bot.loop)) if old_task: old_task.cancel() member = inter.guild.get_member(inter.user.id) or await inter.guild.fetch_member(inter.user.id) role = discord.utils.get(inter.guild.roles, id=COC_NOTIFICATION_ROLE_ID) self.bot.loop.create_task(COC.remove_role_after(member, role, time), name=str(inter.user.id))
def __init__(self): self.arguments = [ { "prompt": "This command will kick people who join your server and aren't in these groups. They must be in __ALL__ of these groups.\n" "Would you like to **add** a new group, **delete** a group, or **view** your current groups?", "name": "choice", "type": "choice", "components": [discord.ui.Select(max_values=1, options=[ discord.SelectOption(label="Add a new group", description="Add a new group to your group-lock."), discord.SelectOption(label="Delete a group", description="Delete a group from your group-lock."), discord.SelectOption(label="View groups", description="View your group-lock."), ])], "choices": ["add a new group", "delete a group", "view groups"] } ] self.permissions = Bloxlink.Permissions().build("BLOXLINK_MANAGER") self.category = "Administration" self.aliases = ["group-lock", "serverlock", "server-lock"] self._range_search = re.compile(r"([0-9]+)\-([0-9]+)")
async def add_emoji_action( ctx: discord.commands.context.ApplicationContext, message: discord.Message): async def custom_emoji_response(button: CustomButton, interaction1: discord.Interaction): m = await ctx.send( embed=discord.Embed(description=self.bot.i18n.get( 'EMOJI_REACTIONS_CUSTOM_EMOJI_MESSAGE'), color=discord.Color.blue())) await ctx.edit(embed=discord.Embed( title=self.bot.i18n.get('EMOJI_REACTIONS_REACT_TO'), description=m.jump_url), view=None) self.activating_reactions[(m.channel.id, m.id)] = (ctx.author.id, ctx, message) async def response(dropdown1: CustomDropdown, interaction1: discord.Interaction): emoji = get(ctx.guild.emojis, id=int(dropdown1.values[0])) if not emoji: raise UnknownException(detail='Emoji not found') await self.add_emoji_reaction_action(ctx.guild, ctx, message, emoji) options = [ discord.SelectOption(label=str(emoji.name), emoji=str(emoji), value=str(emoji.id)) for emoji in ctx.guild.emojis ] pages = [] for i in range(math.ceil(len(options) / 25)): view = discord.ui.View() view.add_item( CustomButton( custom_emoji_response, label=bot.i18n.get( 'EMOJI_REACTIONS_CUSTOM_EMOJI_LABEL'), emoji=bot.i18n.get('EMOJI_REACTIONS_CUSTOM_EMOJI'))) view.add_item( CustomDropdown( response, bot.i18n.get( 'EMOJI_REACTIONS_CHOOSE_EMOJI_PLACEHOLDER'), options[i * 25:(i + 1) * 25])) pages.append(view) paginator = ViewPaginator(pages, hide_empty=True) await ctx.respond(view=paginator.view(), ephemeral=True)
def __init__(self, bot, mapping): self.bot = bot categories = [] for category in mapping: if category is not None: categories.append(discord.SelectOption( label = category.qualified_name.title(), description = category.description) ) super().__init__(placeholder = 'Select a category.', min_values = 1, max_values = 1, options = categories)
def _create_view(self) -> None: """Creates a select with the options needed""" self.view = View(self.ctx.author.id) self.data["incorrect_answers"].append(self.data["correct_answer"]) self.options = random.sample(self.data["incorrect_answers"], k=4) self.correct_index = self.options.index(self.data["correct_answer"]) self.view.add_item( Select(options=[ discord.SelectOption( label=x if len(x) < 50 else x[:47] + "...", value=str(i)) for i, x in enumerate(self.options) ]))
def __init__(self, options, source, placeholder: str, min_val: int, max_val: int): self.source = source self.invoker = source.author choices = [] for option in options: if not option["emoji"]: choices.append( discord.SelectOption(label=option["label"], description=option["description"])) else: choices.append( discord.SelectOption(label=option["label"], description=option["description"], emoji=option["emoji"])) super().__init__(placeholder=placeholder, min_values=min_val, max_values=max_val, options=choices)
async def send_bot_help(self, mapping): """triggers when a `<prefix>help` is called""" ctx = self.context prefix = ctx.bot.command_prefix(ctx.bot, ctx.message)[2] embed = HelpEmbed(str(ctx.me.avatar.url)) if not self.cache: self.cache = ctx.bot.get_formatted_commands() for k, v in self.cache.items(): embed.add_field( name= f"{v['emoji']['normal']} `{k}` ({len(v['commands'])} commands)", value=v['description'], inline=False) embed.add_field( name="** **", value= "\nFor more info to a specific command, use ```css\nhelp <command_name>```", inline=False) view = View(user_id=ctx.author.id, timeout=None) view.add_item( Select([ discord.SelectOption( label=k, value=str(i), emoji=v['emoji']['unicode']) for i, (k, v) in enumerate(self.cache.items()) ], placeholder="Select a command group")) view.add_item( discord.ui.Button(url=ctx.bot.support_server_invite, label="Support server")) view.add_item( discord.ui.Button(url="https://github.com/kile/killua", label="Source code")) view.add_item( discord.ui.Button(url="https://killua.dev", label="Website")) view.add_item( discord.ui.Button(url="https://patreon.com/kilealkuri", label="Premium")) msg = await self.send(embed=embed, view=view, reference=ctx.message, allowed_mentions=discord.AllowedMentions.none()) try: await asyncio.wait_for(view.wait(), timeout=100) except asyncio.TimeoutError: await view.disable(msg) else: #await msg.edit(embed=msg.embeds[0], view=discord.ui.View()) await msg.delete() return await self._send_group_help(view.value, prefix)