Files
revanced-bots/bots/discord/src/commands/fun/reply.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

47 lines
1.6 KiB
TypeScript

import CommandError, { CommandErrorType } from '$/classes/CommandError'
import { ApplicationCommandOptionType, Message } from 'discord.js'
import { ModerationCommand } from '../../classes/Command'
export default new ModerationCommand({
name: 'reply',
description: 'Send a message as the bot',
options: {
message: {
description: 'The message to send',
required: true,
type: ApplicationCommandOptionType.String,
},
reference: {
description: 'The message ID to reply to (use `latest` to reply to the latest message)',
required: false,
type: ApplicationCommandOptionType.String,
},
},
allowMessageCommand: false,
async execute({ logger, executor }, trigger, { reference: ref, message: msg }) {
if (trigger instanceof Message) return
const channel = await trigger.guild!.channels.fetch(trigger.channelId)
if (!channel?.isTextBased())
throw new CommandError(
CommandErrorType.InvalidArgument,
'This command can only be used in or on text channels',
)
const refMsg = ref?.startsWith('latest')
? await channel.messages.fetch({ limit: 1 }).then(it => it.first())
: ref
await channel.send({
content: msg,
reply: refMsg ? { messageReference: refMsg, failIfNotExists: true } : undefined,
})
logger.info(`User ${executor.user.tag} made the bot say: ${msg}`)
await trigger.reply({
content: 'OK!',
ephemeral: true,
})
},
})