Repository navigation
Expand file tree
/
Copy pathtest-trigger.js
More file actions
61 lines (49 loc) · 2.04 KB
/
Copy pathtest-trigger.js
File metadata and controls
61 lines (49 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require('dotenv').config();
const { Client, GatewayIntentBits } = require('discord.js');
const { sendNotify } = require('./src/notifyHandler');
const { createThread } = require('./src/threadHandler');
const TIMEZONE = 'Asia/Seoul';
function printUsageAndExit() {
console.error('사용법: node test-trigger.js <guildId> <channelId> <mode> [mentionRoleIds]');
console.error(' - mode: notify 또는 thread');
console.error(' - mentionRoleIds: 콤마로 구분된 역할 ID 목록 (생략 가능)');
console.error('예시: node test-trigger.js 123456 789012 notify 111111,222222');
process.exit(1);
}
const [guildId, channelId, mode, mentionRoleIdsRaw] = process.argv.slice(2);
if (!guildId || !channelId || !mode) {
printUsageAndExit();
}
if (mode !== 'notify' && mode !== 'thread') {
console.error(`[테스트 실행 실패] mode는 "notify" 또는 "thread"여야 합니다. (입력값: "${mode}")`);
printUsageAndExit();
}
const mentionRoleIds = mentionRoleIdsRaw
? mentionRoleIdsRaw.split(',').map((id) => id.trim()).filter(Boolean)
: [];
const token = process.env.DISCORD_TOKEN;
if (!token) {
console.error('[테스트 실행 실패] .env 파일에 DISCORD_TOKEN이 설정되어 있지 않습니다.');
process.exit(1);
}
const guildConfig = { channelId, mentionRoleIds };
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
});
client.once('clientReady', async () => {
console.log(`[로그인 성공] ${client.user.tag}로 로그인했습니다.`);
console.log(`[테스트 실행] 길드(${guildId}) / 채널(${channelId}) / mode(${mode}) / 태그 역할(${mentionRoleIds.length ? mentionRoleIds.join(', ') : '없음'})`);
try {
if (mode === 'notify') {
await sendNotify(client, guildId, guildConfig, TIMEZONE);
} else {
await createThread(client, guildId, guildConfig, TIMEZONE);
}
} catch (err) {
console.error('[테스트 실행 실패] 예상치 못한 오류:', err.message);
} finally {
client.destroy();
process.exit(0);
}
});
client.login(token);