delete existing message and resend it

This commit is contained in:
Keisuke Hirata 2024-10-20 04:13:19 +09:00
parent 93e2af096d
commit 82311f2bb6
2 changed files with 12 additions and 15 deletions

View File

@ -16,7 +16,7 @@ export default function awardEmbed(reaction: MessageReaction | PartialMessageRea
iconURL: reaction.message.author?.avatarURL() || undefined,
})
.setDescription(reaction.message.content || null)
.setThumbnail(reaction.message.attachments.first()?.url || null)
.setThumbnail(reaction.message.attachments.filter((attachment) => !(!attachment.height && !attachment.width)).first()?.url || null)
.addFields({
name: `${reaction.emoji.name} x${reaction.count} `,
value: `in <#${reaction.message.channelId}> • ${formatTime(reaction.message.createdAt)}\n-# ${reaction.message.id}`,

View File

@ -27,9 +27,6 @@ import {
GatewayIntentBits,
Events,
TextChannel,
Webhook,
WebhookMessageCreateOptions,
WebhookClient,
} from "discord.js";
import { writeConfig, readConfig } from "./config.ts";
const client = new Client({
@ -49,7 +46,7 @@ client.on("ready", () => {
}
console.log(`Logged in as ${client.user.tag}!`);
client.user.setActivity("for reactions");
client.user.setActivity("👑let's award funny messages!");
});
import { Entry, Type } from "./entry.ts";
@ -205,21 +202,21 @@ client.on(Events.MessageReactionAdd, async (reaction, user) => {
if ((entry.channel_type === Type.EXCLUDE) === entry.channels.includes(reaction.message.channelId)) return;
if ((entry.emoji_type === Type.EXCLUDE) === entry.emojis.includes(`${reaction.emoji.name}`)) return;
console.log(`Reaction added: ${reaction.emoji.name} in ${reaction.message.guild.channels.cache.get(reaction.message.channelId)?.name}`);
if (reaction.count === null || reaction.count < entry.count) return;
if (reaction.count === entry.count) {
const attachments = reaction.message.attachments.filter((attachment) => !(!attachment.height && !attachment.width))
const channel = reaction.message.guild.channels.cache.get(entry.output_channel) as TextChannel;
if (!channel) return;
channel.messages.fetch({ limit: 5 }).then((messages) => {
messages.find((message) => {
if (message.embeds[0]?.fields[0].value.includes(reaction.message.id)) {
message.delete();
return true;
}
return false;
});
channel.send({
embeds: [awardEmbed(reaction)]
});
} else if (reaction.count > entry.count) {
}
});
});
client.login(TOKEN);