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, iconURL: reaction.message.author?.avatarURL() || undefined,
}) })
.setDescription(reaction.message.content || null) .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({ .addFields({
name: `${reaction.emoji.name} x${reaction.count} `, name: `${reaction.emoji.name} x${reaction.count} `,
value: `in <#${reaction.message.channelId}> • ${formatTime(reaction.message.createdAt)}\n-# ${reaction.message.id}`, value: `in <#${reaction.message.channelId}> • ${formatTime(reaction.message.createdAt)}\n-# ${reaction.message.id}`,

View File

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