Skip to main content

Class: MessagePrompter<S>

@sapphire/discord.js-utilities.MessagePrompter

This is a MessagePrompter, a utility that sends a message, prompting for user input. The prompt can resolve to any kind of input. There are several specifiable types to prompt for user input, and they are as follows:

  • Confirm This will send a simple Yes/No prompt, using reactions.
  • Number This will prompt for an integer. By default it will be a number between 0 and 10 (inclusive), however you can also specify your own custom range (inclusive).
  • Reactions This can be any kind of reaction emoji that Discord supports, and as many as you want. This type will return that reaction instead of a boolean.
  • Message This will prompt the user and require a response in the form of a message. This can be helpful if you require a user to upload an image for example, or give text input.

You must either use this class directly or extend it.

MessagePrompter uses reactions to prompt for a yes/no answer and returns it. You can modify the confirm and cancel reaction used for each message, or use the {@link MessagePrompter.defaultPrompts}. {@link MessagePrompter.defaultPrompts} is also static so you can modify these directly.

example

const { MessagePrompter } = require('@sapphire/discord.js-utilities');

const handler = new MessagePrompter('Are you sure you want to continue?');
const result = await handler.run(channel, author);

example

const { MessagePrompter, MessagePrompterStrategies } = require('@sapphire/discord.js-utilities');

const handler = new MessagePrompter('Choose a number between 5 and 10?', MessagePrompterStrategies.Number, {
start: 5,
end: 10
});
const result = await handler.run(channel, author);

example

const { MessagePrompter, MessagePrompterStrategies } = require('@sapphire/discord.js-utilities');

const handler = new MessagePrompter('Are you happy or sad?', MessagePrompterStrategies.Reaction, {
reactions: ['๐Ÿ™‚', '๐Ÿ™']
});
const result = await handler.run(channel, author);

example

const { MessagePrompter, MessagePrompterStrategies } = require('@sapphire/discord.js-utilities');

const handler = new MessagePrompter('Do you love me?', MessagePrompterStrategies.Message);
const result = await handler.run(channel, author);

Type parameters

NameType
Sextends keyof StrategyReturns = "confirm"

Constructors

constructor

โ€ข new MessagePrompter<S>(message, strategy?, strategyOptions?)

Constructor for the MessagePrompter class

Type parameters

NameType
Sextends keyof StrategyReturns = "confirm"

Parameters

NameTypeDescription
messagestring | MessageOptions | MessagePrompterBaseStrategy | MessagePayloadThe message to send.
strategy?SThe strategy name or Instance to use
strategyOptions?S extends keyof StrategyOptions ? StrategyOptions[S] : neverThe options that are passed to the strategy

Defined in

projects/utilities/packages/discord.js-utilities/src/lib/MessagePrompter/MessagePrompter.ts:110

Properties

strategy

โ€ข strategy: MessagePrompterBaseStrategy

The strategy used in MessagePrompter.run

Defined in

projects/utilities/packages/discord.js-utilities/src/lib/MessagePrompter/MessagePrompter.ts:102


defaultStrategy

โ–ช Static defaultStrategy: keyof StrategyReturns = 'confirm'

The default strategy to use

Defined in

projects/utilities/packages/discord.js-utilities/src/lib/MessagePrompter/MessagePrompter.ts:169


strategies

โ–ช Static strategies: Map<keyof StrategyReturns, Ctor<[message: string | MessageOptions | MessagePayload, options?: IMessagePrompterConfirmStrategyOptions] | [message: string | MessageOptions | MessagePayload, options: IMessagePrompterNumberStrategyOptions] | [message: string | MessageOptions | MessagePayload, options: IMessagePrompterReactionStrategyOptions] | [message: string | MessageOptions | MessagePayload, options: IMessagePrompterStrategyOptions], MessagePrompterConfirmStrategy | MessagePrompterNumberStrategy | MessagePrompterReactionStrategy | MessagePrompterMessageStrategy>>

The available strategies

Defined in

projects/utilities/packages/discord.js-utilities/src/lib/MessagePrompter/MessagePrompter.ts:149

Methods

run

โ–ธ run<Filter>(channel, authorOrFilter): S extends keyof StrategyReturns ? Promise<StrategyReturns[S]> : never

This executes the MessagePrompter and sends the message.

Type parameters

NameType
Filterextends [MessageReaction, User] | [Message<boolean>]

Parameters

NameTypeDescription
channelMessagePrompterChannelTypesThe channel to use.
authorOrFilterUser | CollectorFilter<Filter>An author object to validate or a CollectorFilter predicate callback.

Returns

S extends keyof StrategyReturns ? Promise<StrategyReturns[S]> : never

Defined in

projects/utilities/packages/discord.js-utilities/src/lib/MessagePrompter/MessagePrompter.ts:137