72 lines
2.7 KiB
JavaScript
72 lines
2.7 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Fetch a Discord message by channel ID and message ID.
|
|
* Usage: node scripts/fetch-message.js <channelId> <messageId>
|
|
*/
|
|
const path = require('path');
|
|
const { Client, GatewayIntentBits } = require('discord.js');
|
|
|
|
require('dotenv').config({ path: path.join(__dirname, '../.env') });
|
|
require('dotenv').config({ path: path.join(__dirname, '../../.env') });
|
|
|
|
const TOKEN = process.env.MEMBER_BOT_TOKEN || process.env.DISCORD_BOT_TOKEN;
|
|
const [channelId, messageId] = process.argv.slice(2);
|
|
|
|
if (!TOKEN || !channelId || !messageId) {
|
|
console.error('Usage: node scripts/fetch-message.js <channelId> <messageId>');
|
|
process.exit(1);
|
|
}
|
|
|
|
const client = new Client({
|
|
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
|
|
});
|
|
|
|
client.once('ready', async () => {
|
|
try {
|
|
const channel = await client.channels.fetch(channelId).catch(() => null);
|
|
if (!channel) {
|
|
console.log('Channel not found or bot cannot access it.');
|
|
process.exit(0);
|
|
}
|
|
const message = await channel.messages.fetch(messageId).catch((err) => null);
|
|
if (!message) {
|
|
console.log('Message not found (wrong channel, deleted, or no access).');
|
|
process.exit(0);
|
|
}
|
|
console.log('Channel:', channel.name, '(' + channel.id + ')');
|
|
console.log('Message ID:', message.id);
|
|
console.log('Author:', message.author.tag, '(' + message.author.id + ')');
|
|
console.log('Created:', message.createdAt ? message.createdAt.toISOString() : message.createdTimestamp);
|
|
console.log('Content:', message.content || '(empty or embed only)');
|
|
if (message.embeds && message.embeds.length) {
|
|
message.embeds.forEach((emb, i) => {
|
|
console.log('\n--- Embed', i + 1, '---');
|
|
if (emb.title) console.log('Title:', emb.title);
|
|
if (emb.description) console.log('Description:', emb.description);
|
|
if (emb.url) console.log('URL:', emb.url);
|
|
if (emb.fields && emb.fields.length) {
|
|
emb.fields.forEach((f) => console.log('Field:', f.name, '\n', f.value));
|
|
}
|
|
if (emb.footer?.text) console.log('Footer:', emb.footer.text);
|
|
// Ticket name for display (e.g. "indifferentketchup🍅" from "indifferentketchup🍅-claimed-7235")
|
|
const ticketNameField = emb.fields?.find((f) => f.name && f.name.toLowerCase().includes('ticket name'));
|
|
if (ticketNameField?.value) {
|
|
const full = ticketNameField.value.trim();
|
|
const short = full.replace(/-claimed-\d+$/, '').trim();
|
|
console.log('Ticket (short):', short || full);
|
|
}
|
|
});
|
|
}
|
|
} catch (e) {
|
|
console.error(e.message || e);
|
|
} finally {
|
|
client.destroy();
|
|
process.exit(0);
|
|
}
|
|
});
|
|
|
|
client.login(TOKEN).catch((e) => {
|
|
console.error('Login failed:', e.message);
|
|
process.exit(1);
|
|
});
|