지난 편에 이어 디스코드 봇 만들기 마무리!
const botToken = process.env.DISCORD_BOT_TOKEN;
const requestURL = `https://discord.com/api/v10/channels/${channelId}/messages/${messageId}/threads`;
const body = {
name: threadName,
auto_archive_duration: 60,
};
await fetch(requestURL, {
method: "POST",
headers: {
Authorization: `Bot ${botToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify(body),
});
디스코드 개발자 페이지에 접속해 new application 생성
생성한 애플리케이션 페이지에서 bot 메뉴 클릭
reset token으로 토큰 생성

생성한 봇을 사용할 채널에 초대하기 위해 OAuth2 > OAuth2 URL Generator에서 URL 생성
scope에서 bot 선택
bot permissions에서 send message, create public
threads, create private threads, send message in threads 선택


하단에 생성된 url로 접속해 서버에 초대
봇을 사용할 채널에서 봇 권한 설정 확인


const requestURL = `${process.env.DISCORD_WEBHOOK_TEST_URL}?thread_id=${threadId}&wait=true`;
const body = {
content,
};
const response = await fetch(requestURL, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(body),
});
결과 화면




0 8 ? * 1-5 2025 입력했더니 아마존 서버시간 기준이라 보내는 시간 예시에 엉뚱한 시간대가 떴다

const getDateText = () => {
const today = new Date();
// 추가한 로직, 한국 시간에 맞게 다음 날 날짜를 가져왔다
today.setDate(today.getDate() + 1);
const month = today.getMonth() + 1;
const date = today.getDate();
const day = today.getDay();
return `${month}/${date} (${dayText[day]})`;
};

그냥 개발자라면 이 정도는 가볍게 자동화 해야지라는 생각으로 시작했는데
나름 코드도 깔끔하게 작성하려고 노력하고 이것 저것 찾아보며 경험한 게 재밌었다
지금 진행하고 있는 프로젝트도 더 재밌게 할 수 있을 것 같다