-
Notifications
You must be signed in to change notification settings - Fork 0
/
rolldice.js
71 lines (64 loc) · 2.12 KB
/
rolldice.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import {
SlashCommandBuilder,
InteractionContextType,
ApplicationIntegrationType,
CommandInteraction // eslint-disable-line no-unused-vars
} from 'discord.js';
import * as util from '../../lib/util.js';
// Set the command as a Global Application Command.
// Include the command when registering global application commands.
export const global = true;
// Create API-compatible JSON data for the command.
export const data = new SlashCommandBuilder()
.setName('rolldice')
.setDescription('Roll dices')
.setDescriptionLocalizations({
'es-ES': 'Tirar los dados'
})
.setContexts(InteractionContextType.Guild)
.setIntegrationTypes(
ApplicationIntegrationType.UserInstall,
ApplicationIntegrationType.GuildInstall
)
.addIntegerOption(opt => opt
.setName('dices')
.setDescription('Dice quantity')
.setDescriptionLocalizations({
'es-ES': 'Cantidad de dados'
})
.setMinValue(1)
.setMaxValue(5)
)
.addIntegerOption(opt => opt
.setName('sides')
.setDescription('Face quantity')
.setDescriptionLocalizations({
'es-ES': 'Cantidad de caras'
})
.setMinValue(2)
.setMaxValue(Number.MAX_SAFE_INTEGER)
);
/**
* Represents a slash command interaction.
* @param {CommandInteraction} interaction
*/
export async function execute(interaction) {
await interaction.reply({
content: '⌛⠀Rolling the dice ...'
});
const dices = interaction.options.getInteger('dices') ?? 1;
const sides = interaction.options.getInteger('sides') ?? 6;
await util.timeout(2000, 5000);
// Avoid using:
// const reply = await interaction.reply({ fetchReply: true });
// await reply.edit(...);
// The above code might throw 'ChannelNotCached' for user apps if
// the command is invoked in a server where the bot is not in.
// https://github.com/discordjs/discord.js/issues/10441
await interaction.editReply(
Array.from(
{ length: dices },
() => `🎲⠀${util.random(1, sides)}`
).join('\n')
);
}