index.js 1.49 KB
const Discord = require('discord.js');	// discord.js 라이브러리 호출
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] })	// Client 객체 생성
const {token} = require('./token');

// discord 봇이 실행될 때 딱 한 번 실행할 코드를 적는 부분
client.on('ready', () => {
    console.log(`Logged in as ${client.user.tag}!`);
  
  });
  
client.on('message', msg => {

      
    try { 
    // !ping 
        if (msg.content === '!ping') msg.channel.send(`pong!`); // 채팅에서 메세지가 들어왔을 때 실행할 콜백함수입니다.

        if (msg.content === '!avatar') msg.channel.send(msg.author.displayAvatarURL()); // 메세지를 보낸 유저의 프로필 사진을 받아옵니다.
        
        if(msg.content === '!help') {
        // 저희는 MessageEmbed 생성자로 embed를 생성할 수 있습니다.
        const embed = new Discord.MessageEmbed()
        .setTitle("이것은 blockchain service bot입니다!") // 1 - embed의 제목을 담당합니다.
        .setColor('0f4c81') // 2 - embed 사이드 바의 색을 정합니다.
        .setDescription('안녕하세요! 이곳은 추후에 설명할 공간입니다.'); // 3 - 실제로 설명을 담당하는 곳입니다.
        console.log(embed);

        msg.channel.send(embed);
    }
        //console.log(msg.author); 사용자 정보가 발생합니다.
    }catch (e) {
        console.log(e);
    }
    
    });
  
// 봇과 서버를 연결해주는 부분
client.login(token);