#Poll cog

1 messages · Page 1 of 1 (latest)

rough saffron
#
import discord
from discord.commands import SlashCommandGroup
from discord.ext import commands


import WiP.cogs.views as views


class Poll(commands.Cog):
    def __init__(self, bot) -> None:
        self.bot = bot

    poll = SlashCommandGroup(name="poll", description="Create a poll")

    @poll.command(name="single")
    async def poll_single(self, interaction: discord.Interaction):
        """Create a single choice poll."""

        await self._poll_callback(interaction, views.PollCreate(), max_values=1)

    @poll.command(name="multiple")
    async def poll_multiple(
            self,
            interaction: discord.Interaction,

    ):
        """Create a multiple choice poll."""

        await self._poll_callback(
            interaction, views.PollCreate()
        )

    @poll.command(name="yes-no")
    async def poll_yes_no(self, interaction: discord.Interaction):
        """Create a "Yes or No" poll."""

        await self._poll_callback(interaction, views.PollYesNoCreate(), max_values=1)

    async def _poll_callback(
            self,
            interaction: discord.Interaction,
            modal: discord.ui.Modal,
            *,
            max_values: int
    ):
        """Callback for poll creation and sending to the channel."""

        await interaction.response.send_modal(modal)
        await modal.wait()

        options = modal.options.value.split("\n")
        max_values = min(max_values, len(options))

        view = views.PollInput(
            author=interaction.user, modal=modal, max_values=max_values
        )
        embed, graph = await view.build_embed()

        await interaction.followup.send(
            embed=embed,
            file=graph,
            view=view,
        )


def setup(bot):
    bot.add_cog(Poll(bot))
hearty condor
#
  1. What isn't working? Are you getting any errors?
  2. That code on GitHub is for discord.py bots, not pycord bots
hearty condor
#

Pycord is it's own API Wrapper, just like discord.py. Pycord is a fork of discord.py so a lot of the stuff is implement the same way, but not all of them.

#

So discord.py and pycord cannot be used at the same time

rough saffron
#

please delete

silk nimbusBOT
#

dynoError No tag close found.

hearty condor
#

.tag close

grave vergeBOT
#

Done with your help thread?

Please close your own help thread by using </close:1009144375709814897> with @gentle storm.

Backup bot: </solved:1109625445990793246> (or .solved) with @grave verge.