async def wait_react( msg: discord.Message, bot: discord.ext.commands.Bot, allowed: Tuple[str, ...] = None, timeout=10.0 ): fut = asyncio.get_running_loop().create_future() async def listener(payload: discord.RawReactionActionEvent): if allowed is not None and str(payload.emoji) not in allowed: return if payload.message_id == msg.id and payload.user_id != bot.user.id: fut.set_result(str(payload.emoji)) bot.add_listener(listener, 'on_raw_reaction_add') bot.add_listener(listener, 'on_raw_reaction_remove') r = await fut # await asyncio.wait_for(fut, timeout) bot.remove_listener(listener, 'on_raw_reaction_add') bot.remove_listener(listener, 'on_raw_reaction_remove') return str(r)
def initialize_bot(self, discord_bot: discord.ext.commands.Bot) -> None: """ initializes a discord bot with commands and listeners on this pseudo cog class :param: discord_bot: the discord_bot to initialize """ discord_bot.add_listener(self.on_ready) discord_bot.add_listener(self.on_message) if self.discord_version_enabled: discord_bot.add_command( Command(self.version, name="version", pass_context=True, ignore_extra=False, help="display the plugin's version information"))
def setup(bot: discord.ext.commands.Bot): bot.add_listener(on_message)