Skip to main content

Class: MessagePrompter<S>

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 MessagePrompter.defaultPrompts. MessagePrompter.defaultPrompts is also static so you can modify these directly.

Examples​

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);
const { MessagePrompter } = require('@sapphire/discord.js-utilities');

const handler = new MessagePrompter('Choose a number between 5 and 10?', 'number', {
start: 5,
end: 10
});
const result = await handler.run(channel, author);
const { MessagePrompter } = require('@sapphire/discord.js-utilities');

const handler = new MessagePrompter('Are you happy or sad?', 'reaction', {
reactions: ['🙂', '🙁']
});
const result = await handler.run(channel, author);
const { MessagePrompter } = require('@sapphire/discord.js-utilities');

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

Type Parameters​

Type ParameterDefault type
S extends keyof StrategyReturns"confirm"

Constructors​

new MessagePrompter()​

new MessagePrompter<S>(message: string | MessagePayload | MessageCreateOptions | MessagePrompterBaseStrategy, strategy?: S, strategyOptions?: S extends keyof StrategyOptions ? StrategyOptions[S<S>] : never): MessagePrompter<S>

Constructor for the MessagePrompter class

Parameters​

ParameterTypeDescription
messagestring | MessagePayload | MessageCreateOptions | MessagePrompterBaseStrategyThe message to send.
strategy?SThe strategy name or Instance to use
strategyOptions?S extends keyof StrategyOptions ? StrategyOptions[S<S>] : neverThe options that are passed to the strategy

Returns​

MessagePrompter<S>

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​

readonly static strategies: Map<keyof StrategyReturns, Ctor<[string | MessagePayload | MessageCreateOptions, IMessagePrompterConfirmStrategyOptions] | [string | MessagePayload | MessageCreateOptions, IMessagePrompterNumberStrategyOptions] | [string | MessagePayload | MessageCreateOptions, IMessagePrompterReactionStrategyOptions] | [string | MessagePayload | MessageCreateOptions, IMessagePrompterStrategyOptions], MessagePrompterConfirmStrategy | MessagePrompterMessageStrategy | MessagePrompterNumberStrategy | MessagePrompterReactionStrategy>>

The available strategies

Defined in​

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

Methods​

run()​

run<Filter>(channel: MessagePrompterChannelTypes, authorOrFilter: User | CollectorFilter<Filter>): S extends keyof StrategyReturns ? Promise<StrategyReturns[S<S>]> : never

This executes the MessagePrompter and sends the message.

Type Parameters​

Type Parameter
Filter extends [MessageReaction, User] | [Message<boolean>]

Parameters​

ParameterTypeDescription
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<S>]> : never

Defined in​

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