가이드 · 디스코드 봇
Node.js 봇 올리기 (discord.js)
index.js + package.json + .env → 시작.
1. 준비
- 봇 토큰: 디스코드 봇 24시간 켜 두기 1번.
- 주문할 때 실행 환경 Node.js 20 · 22 · 24.
2. 파일 세 개
index.js
require('dotenv').config();
const { Client, Events, GatewayIntentBits, REST, Routes, SlashCommandBuilder } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
const commands = [new SlashCommandBuilder().setName('ping').setDescription('응답 속도').toJSON()];
client.once(Events.ClientReady, async (c) => {
await new REST().setToken(process.env.TOKEN).put(Routes.applicationCommands(c.user.id), { body: commands });
console.log(`로그인: ${c.user.tag}`);
});
client.on(Events.InteractionCreate, async (i) => {
if (i.isChatInputCommand() && i.commandName === 'ping') await i.reply(`pong ${client.ws.ping}ms`);
});
client.login(process.env.TOKEN);
package.json
{
"name": "my-bot",
"main": "index.js",
"dependencies": {
"discord.js": "^14",
"dotenv": "^16"
}
}
.env
TOKEN=복사한_토큰
3. 올리기 · 시작
- 서비스 화면 → 패널 열기 → 파일 → 올리기.
node_modules는 올리지 않습니다. - 콘솔 → 시작.
- 콘솔에
package.json 목록을 설치합니다.→봇을 시작합니다: index.js→로그인: …. - 디스코드에서
/ping.
4. 자동으로 해 주는 것
- 시작 파일:
package.json의main→index.js·main.js·bot.js·app.js(src/,.ts포함) →.js가 하나면 그것 →npm start. - 패키지:
package.json이 바뀌면npm install,require·import중 없는 것도 설치. - TypeScript(
.ts)는 그대로 실행됩니다. - 직접 정하기: 패널 시작 설정 → 시작 파일 · 추가 패키지 · 지울 패키지.
5. 메시지 읽는 봇
- Developer Portal → Bot → Message Content Intent 켜기.
intents에GatewayIntentBits.GuildMessages·GatewayIntentBits.MessageContent추가.
6. GitHub에서 받기 (선택)
- 패널 시작 설정 → Git 주소 (비공개면 Git 사용자 이름 · Git 토큰).
- 서버 파일이 비어 있을 때 설정 → 서버 재설치.
- 자동 업데이트
1→ 시작할 때마다git pull.