Files
revanced-bots/bots/discord/src/commands/fun/coinflip.ts
2025-06-23 20:32:18 +07:00

40 lines
1.1 KiB
TypeScript

import Command from '$/classes/Command'
import { applyCommonEmbedStyles } from '$/utils/discord/embeds'
import { EmbedBuilder, MessageFlags } from 'discord.js'
export default new Command({
name: 'coinflip',
description: 'Do a coinflip!',
type: Command.Type.ChatGlobal,
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()],
flags: MessageFlags.Ephemeral,
})
.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: '🐈',
}