diff --git a/src/debug-message.ts b/src/debug-message.ts new file mode 100644 index 0000000..3853a2a --- /dev/null +++ b/src/debug-message.ts @@ -0,0 +1,77 @@ +import process from 'node:process' +import { Client } from 'discord.js-selfbot-v13' +import env from './env.js' + +const link = process.argv[2] +if (!link) { + console.error('Usage: pnpm tsx src/debug-message.ts ') + process.exit(1) +} + +const match = link.match(/channels\/(\d+)\/(\d+)\/(\d+)/) +if (!match) { + console.error('Invalid Discord message link') + process.exit(1) +} + +const [, guildId, channelId, messageId] = match + +const client = new Client() + +client.once('ready', async () => { + console.log(`Logged in as ${client.user?.tag}\n`) + + try { + const guild = client.guilds.cache.get(guildId) + if (!guild) { + console.error(`Guild ${guildId} not found`) + process.exit(1) + } + + const channel = guild.channels.cache.get(channelId) + if (!channel || !('messages' in channel)) { + console.error(`Channel ${channelId} not found or not a text channel`) + process.exit(1) + } + + const message = await channel.messages.fetch(messageId) + + console.log('=== MESSAGE PAYLOAD ===\n') + console.log(JSON.stringify({ + id: message.id, + content: message.content, + author: { + id: message.author.id, + username: message.author.username, + displayName: message.author.displayName, + bot: message.author.bot, + }, + type: message.type, + flags: message.flags.toArray(), + reference: message.reference, + messageSnapshots: (message as any).messageSnapshots, + embeds: message.embeds.map(e => ({ + type: e.type, + title: e.title, + description: e.description?.slice(0, 100), + url: e.url, + author: e.author, + })), + attachments: message.attachments.map(a => ({ + id: a.id, + name: a.name, + contentType: a.contentType, + url: a.url, + })), + components: message.components.length, + }, null, 2)) + } + catch (err) { + console.error('Error fetching message:', err) + } + + client.destroy() + process.exit(0) +}) + +client.login(env.discordToken) diff --git a/src/discord/handlers.ts b/src/discord/handlers.ts index 40822b9..3acc20e 100644 --- a/src/discord/handlers.ts +++ b/src/discord/handlers.ts @@ -18,6 +18,10 @@ async function handleMessage(message: Message): Promise { if (!message.guild) return + // Skip forwarded messages + if ((message.reference as any)?.type === 'FORWARD') + return + const serverConfig = config.servers.find((s: { guildId: string }) => s.guildId === message.guild!.id) if (!serverConfig) return