fix: actually add mimic 😢
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
import { ChatInputCommandInteraction, MessageCreateOptions, MessageFlags, SlashCommandBuilder, TextChannel } from "discord.js";
|
||||
import { Command } from "../../commands";
|
||||
|
||||
const builder = new SlashCommandBuilder()
|
||||
.setName('bot-mimic')
|
||||
.setDescription('Makes the bot send a message')
|
||||
.addStringOption(opt =>
|
||||
opt
|
||||
.setName('content')
|
||||
.setDescription('The text content of the message')
|
||||
.setRequired(false)
|
||||
)
|
||||
.addAttachmentOption(opt =>
|
||||
opt
|
||||
.setName('attachment')
|
||||
.setDescription('An attachment for the message')
|
||||
.setRequired(false)
|
||||
)
|
||||
.addStringOption(opt =>
|
||||
opt
|
||||
.setName('reply')
|
||||
.setDescription('The message ID that the bot should reply to')
|
||||
.setRequired(false)
|
||||
);
|
||||
|
||||
|
||||
const command: Command = {
|
||||
name: 'bot-mimic',
|
||||
builder: builder,
|
||||
ownerOnly: true,
|
||||
execute: async (interaction: ChatInputCommandInteraction): Promise<void> => {
|
||||
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||
|
||||
if (!interaction.channel?.isTextBased()) {
|
||||
await interaction.editReply('This command can only be used in a text channel.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!interaction.channel.isSendable()) {
|
||||
await interaction.editReply('Channel is not sendable');
|
||||
return;
|
||||
}
|
||||
|
||||
const content = interaction.options.getString('content');
|
||||
const attachment = interaction.options.getAttachment('attachment');
|
||||
const replyId = interaction.options.getString('reply');
|
||||
|
||||
if (!content && !attachment) {
|
||||
await interaction.editReply('Unable to send empty message. Specify content or attachment, or both.');
|
||||
return;
|
||||
}
|
||||
|
||||
const channel = interaction.channel as TextChannel;
|
||||
const message: MessageCreateOptions = {};
|
||||
|
||||
if (content) {
|
||||
message.content = content;
|
||||
}
|
||||
|
||||
if (replyId) {
|
||||
try {
|
||||
const replyMessage = await channel.messages.fetch(replyId);
|
||||
message.reply = {
|
||||
messageReference: replyMessage.id
|
||||
};
|
||||
} catch {
|
||||
await interaction.editReply('Invalid message ID for reply.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (attachment) {
|
||||
message.files = [{
|
||||
attachment: attachment.proxyURL,
|
||||
name: attachment.name
|
||||
}];
|
||||
}
|
||||
|
||||
try {
|
||||
await channel.send(message);
|
||||
await interaction.editReply('Message sent successfully.');
|
||||
} catch (error) {
|
||||
console.error('Failed to send message:', error);
|
||||
await interaction.editReply('Failed to send message.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default command;
|
||||
|
||||
Reference in New Issue
Block a user