Skip to content

Add "wait_for()" and "wait_until_ready()" to fluxer.Client #74

@SuperSajuuk

Description

@SuperSajuuk

Type of Feature Request

Code

Describe the feature you would like to see implemented.

A method to be able to wait for a specific event to be dispatched by the Websocket/Gateway (see example code), with a helper method that handles waiting until on_ready is dispatched (the helper method would simply be a wrapper around wait_for("ready")).

I had a look in the code but couldn't seem to find any reference to wait_for, other than a generic asyncio.wait_for that doesn't fit this specific feature request.

Why do you think this feature would be beneficial?

Being able to wait for arbitrary events from the Websocket/Gateway allows for more complex functionality to be built, like interactive workflows with bot commands where the bot waits for user input in chat, or for reactions if that is the user input method. For example "please type the name of a channel to post an announcement in" and the bot waits for a message from the user so they can just type #MyChannelNameHere and the bot parses that as a channel mention and acts accordingly.

Obviously this has to have "timeouts" so you don't wait forever, also a predicate/lambda function check which can be used to determine the conditions for which the wait_for works on.

wait_until_ready() is mostly useful for startup routines where you want functionality to not be available in the bot, until the bot has actually had its internal state and cache filled up. This has to have a warning about not using it in setup_hook() if subclassing the Client or Bot class though: as this is called before the bot can ever be "ready", this would cause a deadlock.

Below is an example of the general "wait_for" syntax that would be nice to have (copied from discord.py implementation):

# Wait for channel
confirm = await ctx.send(":ok_hand: Please type the ID or mention of a channel where this announcement should go.")
try:
	msg = await ctx.bot.wait_for('message', check=lambda x: x.author.id == ctx.author.id and x.guild.id == ctx.guild.id, timeout=60.0)
except asyncio.TimeoutError:
	await confirm.edit(content=":no_entry_sign: You did not respond in time so this operation has been cancelled.")
	return

No Duplicates

  • I believe this is not a duplicate request.

Attachments

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions