Class: MessagePrompter<S>
Defined in: projects/utilities/packages/discord.js-utilities/src/lib/MessagePrompter/MessagePrompter.ts:98
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 Parameter | Default type |
---|---|
S extends keyof StrategyReturns | "confirm" |
Constructors
new MessagePrompter()
new MessagePrompter<
S
>(message
:string
|MessagePayload
|MessageCreateOptions
|MessagePrompterBaseStrategy
,strategy
?:S
,strategyOptions
?:S
extends keyofStrategyOptions
?StrategyOptions
[S
<S
>] :never
):MessagePrompter
<S
>
Defined in: projects/utilities/packages/discord.js-utilities/src/lib/MessagePrompter/MessagePrompter.ts:110
Constructor for the MessagePrompter class
Parameters
Parameter | Type | Description |
---|---|---|
message | string | MessagePayload | MessageCreateOptions | MessagePrompterBaseStrategy | The message to send. |
strategy ? | S | The strategy name or Instance to use |
strategyOptions ? | S extends keyof StrategyOptions ? StrategyOptions [S <S >] : never | The options that are passed to the strategy |
Returns
Properties
strategy
strategy:
MessagePrompterBaseStrategy
Defined in: projects/utilities/packages/discord.js-utilities/src/lib/MessagePrompter/MessagePrompter.ts:102
The strategy used in MessagePrompter.run
defaultStrategy
static
defaultStrategy: keyofStrategyReturns
='confirm'
Defined in: projects/utilities/packages/discord.js-utilities/src/lib/MessagePrompter/MessagePrompter.ts:169
The default strategy to use
strategies
readonly
static
strategies:Map
<keyofStrategyReturns
,Ctor
<[string
|MessagePayload
|MessageCreateOptions
,IMessagePrompterConfirmStrategyOptions
] | [string
|MessagePayload
|MessageCreateOptions
,IMessagePrompterNumberStrategyOptions
] | [string
|MessagePayload
|MessageCreateOptions
,IMessagePrompterReactionStrategyOptions
] | [string
|MessagePayload
|MessageCreateOptions
,IMessagePrompterStrategyOptions
],MessagePrompterConfirmStrategy
|MessagePrompterMessageStrategy
|MessagePrompterNumberStrategy
|MessagePrompterReactionStrategy
>>
Defined in: projects/utilities/packages/discord.js-utilities/src/lib/MessagePrompter/MessagePrompter.ts:149
The available strategies
Methods
run()
run<
Filter
>(channel
:MessagePrompterChannelTypes
,authorOrFilter
:User
|CollectorFilter
<Filter
>):S
extends keyofStrategyReturns
?Promise
<StrategyReturns
[S
<S
>]> :never
Defined in: projects/utilities/packages/discord.js-utilities/src/lib/MessagePrompter/MessagePrompter.ts:137
This executes the MessagePrompter and sends the message.
Type Parameters
Type Parameter |
---|
Filter extends [MessageReaction , User ] | [Message ] |
Parameters
Parameter | Type | Description |
---|---|---|
channel | MessagePrompterChannelTypes | The channel to use. |
authorOrFilter | User | CollectorFilter <Filter > | An author object to validate or a CollectorFilter predicate callback. |
Returns
S
extends keyof StrategyReturns
? Promise
<StrategyReturns
[S
<S
>]> : never