Utility bot for rhythm game D4DJ. (Note that some dependencies are not public)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
miyu-bot/miyu_bot/commands/common/reaction_message.py

33 lines
1.2 KiB

import asyncio
from typing import List, Callable, Awaitable
import discord
from discord import Message, Embed, Emoji
from discord.ext.commands import Context
async def run_tabbed_message(ctx: Context, message: Message, emojis: List[Emoji], embeds: List[Embed], timeout=300):
async def callback(emoji, _ctx, _message):
await message.edit(embed=embeds[emojis.index(emoji)])
await run_reaction_message(ctx, message, emojis, callback, timeout)
async def run_reaction_message(ctx: Context, message: Message, emojis: List[Emoji],
callback: Callable[[Emoji, Context, Message], Awaitable[None]], timeout=300):
for emoji in emojis:
await message.add_reaction(emoji)
def check(rxn, usr):
return usr == ctx.author and rxn.emoji in emojis and rxn.message.id == message.id
while True:
try:
reaction, user = await ctx.bot.wait_for('reaction_add', timeout=timeout, check=check)
await callback(reaction.emoji, ctx, message)
await message.remove_reaction(reaction, user)
except asyncio.TimeoutError:
for emoji in emojis:
await message.remove_reaction(ctx.bot.get_emoji(emoji), ctx.bot.user)
break