Last active
November 12, 2022 01:07
-
-
Save GRAYgoose124/9c7dc0afd073be2a9af5608a14faf55b to your computer and use it in GitHub Desktop.
consider the changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import discord | |
import asyncio | |
from discord import app_commands | |
from discord.ext import commands | |
class VoteOptions(discord.ui.Select): | |
def __init__(self): | |
self.option = None | |
options = [ | |
discord.SelectOption(label="Amendment", value="Has the council vote on the charter amendment proposal."), | |
discord.SelectOption(label="Bill", value="Has the council vote on the bill proposal."), | |
discord.SelectOption(label="Motion", value="Has the council vote on the motion."), | |
discord.SelectOption(label="Nomination", value="Has the council vote on the nomination of a person to a position."), | |
discord.SelectOption(label="Resolution", value="Has the council vote on the resolution.") | |
] | |
super().__init__(placeholder="Select a vote type", options=options) | |
async def callback(self, interaction: discord.Interaction) -> None: | |
self.option = interaction.data["values"][0] | |
class VoteView(discord.ui.View): | |
def __init__(self, vote_options: VoteOptions): | |
super().__init__() | |
self.add_item(vote_options) | |
class ContextTest(commands.Cog, VoteOptions): | |
def __init__(self, bot: commands.Bot) -> None: | |
self.bot: commands.Bot = bot | |
self.bot.tree.add_command(app_commands.ContextMenu(name='Context Test', callback=self.context_menu_callback)) | |
super().__init__() | |
@commands.command() | |
async def test(self, ctx: commands.Context) -> None: | |
interaction = await ctx.send('Test') | |
await self.context_menu_callback(ctx, interaction, ctx.message) | |
async def context_menu_callback(self, interaction: discord.Interaction, message: discord.Message) -> None: | |
view = VoteView(self) | |
await interaction.response.send_message('Select the vote type below', view=view, ephemeral=True) | |
while self.option is None: | |
await asyncio.sleep(0.1) | |
'''When the option is set, continue''' | |
else: | |
embed = discord.Embed( | |
description = f'**Vote on the {self.options}**', | |
colour=discord.Color.dark_blue() | |
) | |
embed.set_footer(text=f'Vote started by {interaction.author.mention}', icon_url=interaction.author.avatar) | |
await message.reply(embed=embed) | |
pass | |
pass | |
async def setup(bot: commands.Bot) -> None: | |
await bot.add_cog(ContextTest(bot)) | |
async def teardown(bot: commands.Bot) -> None: | |
await bot.remove_cog('ContextTest') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment