봇 명령어가 호스팅 환경에서 동작하지 않을 때 대응 가이드

2026년 1월 24일·4개 메시지

이 글은 호스팅한 디스코드 봇에서 명령어가 반응하지 않을 때 내가 적용한 원인 분석과 해결 절차를 정리한다. 특히 호스팅 환경에서는 로컬 콘솔에 의존한 명령 처리 방식이 작동하지 않을 수 있어, 파일 기반 명령 등록슬래시 명령 등록 절차를 중심으로 설명한다.

증상

  • 봇이 온라인으로 표시되지만 명령어(슬래시 또는 접두사 기반)가 동작하지 않음.
  • 호스팅 화면(또는 제공 콘솔)에 사용자의 명령 입력으로 반응하는 로그가 없음.
  • 로컬에서 콘솔로 명령을 넣어 테스트하면 정상 동작하지만 호스팅 환경에서는 반응 없음.

원인

  • 호스팅 환경에서 개발자가 의존한 대화형 콘솔(stdin) 입력 방식이 제공되지 않거나 실행 중인 프로세스에 연결되어 있지 않음. 즉, 콘솔에 직접 입력해서 트리거하는 방식은 호스팅에서 동작하지 않음.
  • 슬래시 명령을 코드에만 구현해두고 Discord에 **등록(배포)**하지 않았거나, 등록 절차가 생략되어 클라이언트에서 명령이 인식되지 않음.
  • 접두사 기반 명령을 사용할 때 필수 Gateway Intent(예: MessageContent)가 활성화되어 있지 않음.

해결 방법

1단계: 파일 기반 명령 구조로 전환하고 슬래시 명령 등록

  • 프로젝트 루트에 commands/ 폴더를 만들고 각 명령을 파일로 분리한다.
  • discord.js v14 기준 예시(슬래시 명령 ping):
// commands/ping.js
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
  data: new SlashCommandBuilder().setName('ping').setDescription('pong'),
  async execute(interaction) {
    await interaction.reply('Pong!');
  },
};
  • 봇 시작 파일에서 파일을 읽어 명령 컬렉션을 구성하고 interactionCreate 이벤트로 처리:
// index.js
const fs = require('fs');
const { Client, Collection, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(f => f.endsWith('.js'));
for (const file of commandFiles) {
  const cmd = require(`./commands/${file}`);
  client.commands.set(cmd.data.name, cmd);
}

client.on('interactionCreate', async interaction => {
  if (!interaction.isChatInputCommand()) return;
  const cmd = client.commands.get(interaction.commandName);
  if (!cmd) return;
  await cmd.execute(interaction);
});

client.login(process.env.BOT_TOKEN);
  • 슬래시 명령을 Discord에 등록하는 배포 스크립트 작성:
// deploy-commands.js
const { REST, Routes } = require('discord.js');
const commands = [require('./commands/ping').data.toJSON()];
const rest = new REST({ version: '10' }).setToken(process.env.BOT_TOKEN);
(async () => {
  await rest.put(Routes.applicationCommands(process.env.CLIENT_ID), { body: commands });
  console.log('Commands deployed');
})();
  • 위 스크립트를 호스팅에서 한 번 실행해 슬래시 명령을 배포한다.

2단계: 호스팅 특성에 맞춘 배포·설정 점검

  • 호스팅 서비스(예: 디스호스트)에 프로젝트 파일을 업로드하고 시작 커맨드를 설정한 뒤 앱을 재시작한다. 호스팅 콘솔은 보통 stdin으로 명령 입력을 받지 못하므로 파일/코드 기반으로 모든 명령을 처리해야 한다.
  • 접두사 기반 명령을 쓴다면 MessageContent intent를 코드와 개발자 포털에서 활성화한다.
  • 환경변수(BOT_TOKEN, CLIENT_ID, GUILD_ID 등)를 호스팅 관리자 페이지에 등록하고 보안 유출에 유의한다.
  • 로그를 확인해 권한 문제(봇 권한, OAuth scope에 applications.commands 포함 여부)나 버전 불일치(node, 라이브러리)를 점검한다.

마무리

호스팅 환경에서는 콘솔 입력에 의존하지 말고 파일 기반 명령 구현과 슬래시 명령 등록으로 전환하면 안정적으로 동작한다. 디스코드 봇을 디스호스트 같은 플랫폼에 올릴 때는 배포·환경변수·인텐트를 반드시 점검하라.