52 lines
1.6 KiB
JavaScript
52 lines
1.6 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Fetch a Discord channel by ID and print its name and type.
|
|
* Usage: node scripts/fetch-channel.js <channelId>
|
|
* Example: node scripts/fetch-channel.js 1335424071227281520
|
|
*
|
|
* Uses DISCORD_BOT_TOKEN or MEMBER_BOT_TOKEN from .env (broccolini-bot or parent).
|
|
*/
|
|
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 = process.argv[2];
|
|
|
|
if (!TOKEN) {
|
|
console.error('❌ No bot token (DISCORD_BOT_TOKEN or MEMBER_BOT_TOKEN)');
|
|
process.exit(1);
|
|
}
|
|
if (!channelId) {
|
|
console.error('Usage: node scripts/fetch-channel.js <channelId>');
|
|
process.exit(1);
|
|
}
|
|
|
|
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
|
|
|
client.once('ready', async () => {
|
|
try {
|
|
const channel = await client.channels.fetch(channelId).catch((err) => null);
|
|
if (!channel) {
|
|
console.log('Channel not found or bot cannot access it.');
|
|
process.exit(0);
|
|
}
|
|
console.log('Channel ID:', channel.id);
|
|
console.log('Name:', channel.name);
|
|
console.log('Type:', channel.type);
|
|
if (channel.guild) console.log('Guild:', channel.guild.name, `(${channel.guild.id})`);
|
|
} 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);
|
|
});
|