Last active
January 8, 2022 17:29
-
-
Save PikalaxALT/2da77dddb6a34d8226ae5decc10a5b2b to your computer and use it in GitHub Desktop.
This file contains 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 asyncio | |
import discord | |
from discord.ext import commands | |
from collections import Counter | |
class FooCog: | |
THUMBS_UP = '\U0001ff4d' | |
THUMBS_DOWN = '\U0001ff4e' | |
def __init__(self, bot: commands.Bot): | |
self.bot = bot | |
@commands.group(pass_context=True) | |
async def foo(self, ctx: commands.Context): | |
"""Group docs""" | |
@foo.command() | |
async def bar(self, ctx: commands.Context): | |
"""Subcommand docs""" | |
msg: discord.Message = await ctx.send(f'Voting has begun: React with {self.THUMBS_UP} or {self.THUMBS_DOWN}') | |
await msg.add_reaction(self.THUMBS_UP) | |
await msg.add_reaction(self.THUMBS_DOWN) | |
await asyncio.sleep(120) | |
await msg.remove_reaction(self.THUMBS_UP) | |
await msg.remove_reaction(self.THUMBS_DOWN) | |
msg = await ctx.get_message(msg.id) | |
votes = Counter({str(reaction.emoji): reaction.count for reaction in msg.reactions}) | |
await ctx.send(f'Total votes:\n' | |
f'{self.THUMBS_UP}: {votes[self.THUMBS_UP]:d}\n' | |
f'{self.THUMBS_DOWN}: {votes[self.THUMBS_DOWN]:d}') | |
def setup(bot: commands.Bot): | |
bot.add_cog(FooCog(bot)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment