Waiters

Module that holds methods related to discord’s bot client method wait_for They’re useful for retrieving information from users. This functions and classes expect at least discord.Context so they’re have to be use with the commands extension.

class dpytools.waiters.BaseLock(ctx: discord.ext.commands.context.Context, channel: Optional[Union[discord.channel.TextChannel, discord.abc.PrivateChannel]] = None, lock: Union[discord.role.Role, discord.user.User, discord.member.Member, bool] = True)

Callable class to use with the :check: parameter in client.wait_for(‘message’)

The default behavior only requires to pass the context in the constructor and will perform these checks:
  • ctx.author == message.author and ctx.channel == message.channel

If channel is passed then it will check channel == message.channel

If lock parameter is passed (differently than True) then it’ll check the object against message.author.

The constructor Raises ValueError if channel is not a GuildChannel when lock is type Role.

await dpytools.waiters.wait_for_author(ctx: discord.ext.commands.context.Context, stop: str = 'cancel', timeout: Optional[int] = 30)Optional[discord.message.Message]

This function returns a single message from ctx.author in ctx.channel.

Parameters
  • ctx (discord.ext.commands.Context) – the command context

  • stop (str (defaults to ‘cancel’)) – String to stop this function

  • timeout (int (seconds)) – time in seconds to wait for a reply or None if the function should wait forever (usual maximum is a day)

Returns

The user’s reply message.

None if timeout is reached or if stop string is passed

Return type

Optional[discord.Message]

await dpytools.waiters.wait_for_regex(ctx: discord.ext.commands.context.Context, pattern: str, ignore_case: bool = False, timeout: int = 30, channel: Optional[Union[discord.channel.TextChannel, discord.abc.PrivateChannel]] = None, lock: Union[discord.role.Role, discord.member.Member, bool] = True)Optional[discord.message.Message]

Waits for a message that contains a match for the passed :param pattern:

Parameters
  • ctx (discord.ext.commands.Context) – The command context

  • pattern (str) – Regex string to look in the message

  • ignore_case (bool) – Defaults to False. If True sets re.I as flag.

  • timeout (int (seconds)) – Time in seconds to wait for the appropriate message

  • channel (discord.TextChannel) – The channel where the message should come from. Defaults to ctx.channel.

  • lock

    • discord.Role -> Only members with this role can answer

    • discord.Member -> only specified member can answer

    • bool: True -> Only ctx.author can answer

    • bool: False -> Anyone can answer as long as its in the correct channel within the timeout window

Returns

Returns None if timeout is specified and reached and the rest of the checks arent passed or no match for the pattern is found

Return type

Optional[discord.Message]