스튜디오에서 조립한 블록 디스코드 봇을 실시간으로 테스트해볼 수 있는 가상 공간입니다.
/명령어이름 형태로 입력하세요./**
* ==============================================================================
* SnapBot Generated Discord Bot Source Code
* Project Name: My Discord Bot
* Generated Date: 2026-11-03T14:48:54.173Z
* Target Engine: discord.js v14 (Node.js 18+ / 20+ / 22+)
*
* Generated with SnapBot Studio - https://snapbot.koharu.live
* Open Source & Zero-Base Visual Discord Bot IDE by Workshop-Koharu
* ==============================================================================
*/
import {
Client,
GatewayIntentBits,
Partials,
EmbedBuilder,
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
REST,
Routes,
SlashCommandBuilder,
} from 'discord.js';
// ------------------------------------------------------------------------------
// 1. Client Initialization & Gateway Intents
// ------------------------------------------------------------------------------
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
});
// ------------------------------------------------------------------------------
// 2. In-Memory Variables & Persistent Database Storage
// ------------------------------------------------------------------------------
const variables: Record<string, any> = {
score: 0,
prefix: '!',
};
class BotStorage {
private memoryStore: Map<string, any> = new Map();
async get(key: string): Promise<any> {
return this.memoryStore.get(key) ?? null;
}
async set(key: string, value: any): Promise<void> {
this.memoryStore.set(key, value);
console.log(`[SnapBot DB] Saved: ${key} = ${JSON.stringify(value)}`);
}
}
const database = new BotStorage();
// ------------------------------------------------------------------------------
// 3. Slash Command Registration
// ------------------------------------------------------------------------------
const slashCommandList = ["ping"];
async function registerSlashCommands() {
if (slashCommandList.length === 0) return;
const token = process.env.DISCORD_BOT_TOKEN;
const clientId = process.env.DISCORD_CLIENT_ID;
if (!token || !clientId) {
console.warn('[SnapBot] DISCORD_BOT_TOKEN 또는 DISCORD_CLIENT_ID 환경변수가 설정되지 않아 슬래시 명령어를 자동 등록할 수 없습니다.');
return;
}
const commands = slashCommandList.map((name) =>
new SlashCommandBuilder()
.setName(name)
.setDescription(`SnapBot ${name} 슬래시 명령어`)
.toJSON()
);
const rest = new REST({ version: '10' }).setToken(token);
try {
console.log('[SnapBot] 글로벌 슬래시 명령어 등록을 시작합니다...');
await rest.put(Routes.applicationCommands(clientId), { body: commands });
console.log(`[SnapBot] ${commands.length}개의 슬래시 명령어가 성공적으로 등록되었습니다.`);
} catch (error) {
console.error('[SnapBot] 슬래시 명령어 등록 중 오류 발생:', error);
}
}
// ------------------------------------------------------------------------------
// 4. Assembled Visual Event Listeners
// ------------------------------------------------------------------------------
client.once('ready', async () => {
console.log(`[SnapBot] 봇이 준비되었습니다: ${client.user?.tag}`);
if (typeof message !== 'undefined') {
await message.channel.send({ content: "SnapBot 봇이 준비되었습니다. 슬래시 명령어를 사용해 보세요." });
} else if (typeof interaction !== 'undefined' && interaction.channel) {
await interaction.channel.send({ content: "SnapBot 봇이 준비되었습니다. 슬래시 명령어를 사용해 보세요." });
}
});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isChatInputCommand()) return;
if (interaction.commandName === 'ping') {
if (typeof interaction !== 'undefined' && interaction.isRepliable()) {
await interaction.reply({ content: "Pong! SnapBot이 0.05초만에 응답했습니다." });
} else if (typeof message !== 'undefined') {
await message.reply({ content: "Pong! SnapBot이 0.05초만에 응답했습니다." });
}
}
});
// ------------------------------------------------------------------------------
// 5. Bot Startup & Login
// ------------------------------------------------------------------------------
const token = process.env.DISCORD_BOT_TOKEN;
if (!token) {
console.error('[SnapBot Error] DISCORD_BOT_TOKEN 환경변수가 설정되지 않았습니다.');
console.error('.env 파일에 DISCORD_BOT_TOKEN=YOUR_BOT_TOKEN 을 입력해주세요.');
process.exit(1);
}
registerSlashCommands();
client.login(token);
npm install && npm start 로 즉시 실행 가능합니다.스튜디오에서 조립한 블록 디스코드 봇을 실시간으로 테스트해볼 수 있는 가상 공간입니다.
/명령어이름 형태로 입력하세요.