Skip to content

Instantly share code, notes, and snippets.

@PikalaxALT
Last active January 8, 2022 17:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PikalaxALT/2da77dddb6a34d8226ae5decc10a5b2b to your computer and use it in GitHub Desktop.
Save PikalaxALT/2da77dddb6a34d8226ae5decc10a5b2b to your computer and use it in GitHub Desktop.
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