부스 서비스를 운영중 특정 이벤트에 대해 관리자에게 알림을 보내줄 필요가 있었는데 평소 커뮤니케이션에 주로 이용하는 discord에 알림을 받을 채널을 만들어 사용하게 되었다.
npm install discord-webhook-node
import { Webhook } from 'discord-webhook-node'; //패키지 추가
//디스코드 메세지 보내는 함수
async sendingMsg(){
try {
await this.contributeRepository.save(contribute);
const hook = new Webhook(
'위에서 복사한 URL',
);
const message = 'test';
try {
await hook
.send(message)
.then(() => console.log('메시지가 성공적으로 전송되었습니다.'))
.catch((err) => console.log(err.message));
} catch (error) {
console.error(`메시지 전송 실패. 에러: ${error.message}`);
}
}