Files
revanced-bots/bots/discord/src/commands/fun/coinflip.ts
PalmDevs 646ec8da87 feat(bots/discord): framework changes and new features
- Migrated to a new command framework which looks better and works better
- Fixed commands not being bundled correctly
- Added message (prefix) commands with argument validation
- Added a new CommandErrorType, for invalid arguments
- `/eval` is now a bit safer
- Corrected colors for the coinflip embed
- `/stop` now works even when the bot is not connected to the API
2024-07-30 21:15:36 +07:00

40 lines
1.1 KiB
TypeScript

import { EmbedBuilder } from 'discord.js'
import Command from '$/classes/Command'
import { applyCommonEmbedStyles } from '$/utils/discord/embeds'
export default new Command({
name: 'coinflip',
description: 'Do a coinflip!',
global: true,
requirements: {
defaultCondition: 'pass',
},
allowMessageCommand: true,
async execute(_, trigger) {
const result = Math.random() < 0.5 ? ('heads' as const) : ('tails' as const)
const embed = applyCommonEmbedStyles(new EmbedBuilder().setTitle('Flipping... 🪙'), false, false, true)
const reply = await trigger
.reply({
embeds: [embed.toJSON()],
})
.then(it => it.fetch())
embed.setTitle(`The coin landed on... **${result.toUpperCase()}**! ${EmojiMap[result]}`)
setTimeout(
() =>
reply.edit({
embeds: [embed.toJSON()],
}),
1500,
)
},
})
const EmojiMap: Record<'heads' | 'tails', string> = {
heads: '🤯',
tails: '🐈',
}