Files
revanced-bots/bots/discord/src/commands/fun/reply.ts
2025-07-12 01:06:45 +07:00

47 lines
1.6 KiB
TypeScript

import { ApplicationCommandOptionType, Message, MessageFlags } from 'discord.js'
import CommandError, { CommandErrorType } from '$/classes/CommandError'
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!',
flags: MessageFlags.Ephemeral,
})
},
})