본문 바로가기
C C++

c++ 디스코드 봇 만들기

by AYAYz 2019. 12. 30.

C++로 디스코드 봇 만드는 방법

yourWaifu님의 디스코드 라이브러리를 사용할 것 입니다.

 


준비물

필요한 것은 CMake와 OpenSSL 라이브러리, 비주얼 스튜디오가 필요합니다. (또는 C++컴파일러)

Cmake 다운로드: https://cmake.org/download/

 

Download | CMake

Current development distribution Each night binaries are created as part of the testing process. Other than passing all of the tests in CMake, this version of CMake should not be expected to work in a production environment. It is being produced so that us

cmake.org

OpenSSL 다운로드 : https://slproweb.com/download/Win64OpenSSL-1_1_1d.exe

불러오는 중입니다...

(2019/12/30 기준 최신 버전입니다. 아래 링크에서 직접 찾아서 다운가능. Light 버전만은 다운하지 말아야함)

https://slproweb.com/products/Win32OpenSSL.html

Win32/Win64 OpenSSL Installer for Windows - Shining Light Productions

Minimum system requirements: Windows XP or later 32MB RAM 200MHz CPU 30MB hard drive space Recommended system requirements: Windows XP or later 128MB RAM 500MHz CPU 50MB hard drive space September 13, 2018 - Visual Studio 2017 is being used for builds mean

slproweb.com

Download | CMake

Current development distribution Each night binaries are created as part of the testing process. Other than passing all of the tests in CMake, this version of CMake should not be expected to work in a production environment. It is being produced so that us

cmake.org

 

 


 

폴더 하나를 만들고 안에 들어가서 아래 명령어를 입력

git clone https://github.com/yourWaifu/sleepy-discord.git

 

cpp 파일 한개 만들어서 아래와 같이 코드 입력  (예제 코드입니다)

discord.cpp---------------------------------

#include "sleepy_discord/websocketpp_websocket.h"

class MyClientClass : public SleepyDiscord::DiscordClient {
public:
	using SleepyDiscord::DiscordClient::DiscordClient;
	void onMessage(SleepyDiscord::Message message) override {
		if (message.startsWith("whcg hello"))
			sendMessage(message.channelID, "Hello " + message.author.username);
	}
};

int main() {
	MyClientClass client("token", 2); //토큰 바꿔야함
	client.run();
}

토큰 바꿔주셔야합니다.

(토큰은 https://infotech-2.tistory.com/14 에서 참조)

 

그리고 CMakeLists.txt 라는 파일을 만들어줍니다.

그리고 아래와 같이 입력해줍니다

cmake_minimum_required (VERSION 3.6)

project(example)

add_executable(replace-me source.cpp)

add_subdirectory(path/to/sleepy-discord)

target_link_libraries(replace-me sleepy-discord)

 

저의 경우에는

cmake_minimum_required (VERSION 3.6)

project(discord)

add_executable(discord discord.cpp)

add_subdirectory(sleepy-discord) //clone 해서 얻은 sleepy-discord 라이브러리 주소를 넣어줍니다

target_link_libraries(discord sleepy-discord)

로 하였습니다.

 

(현 상황)

 

 

 

 

CMake 열어줍니다. (GUI를 사용할 것입니다)

 

 

맨 위에 source code는 여러분 프로젝트 루트 위치로 하시고 아래꺼는 프로젝트에서 build 라는 폴더 만들어서

거기로 위치 지정해주시면됩니다.  그리고 아래쪽에 Generate를 눌러줍니다.

 

 

 

원하시는대로. 저는 이렇게 그대로.

Finish를 눌러줍니다.

그리고 기다려줍니다 

 

 

아래쪽 로그에 Configuring done Generating done이 뜨셨으면 잘 된겁니다.

만약 오류가 나셨는데 OpenSSL 관련 오류라면 

 

 

Add Entry를 눌러주신 뒤

 

 

(Value에서 /path/to 부분은 openssl 위치입니다.)

 

build 폴더에 들어가줍니다.

 

 

sln 파일을 열어줍니다.

 

자신의 프로젝트를 우클릭 하신 뒤 빌드 (시간 좀 걸림)

그리고 Ctrl + F5를 눌러 디버그 하지 않고 실행을 해줍니다.

 

 

 

그리고 생긴 이 discord.exe를 실행해주면 봇이 켜집니다.

 

 

 

 

음 잘됩니다.

 

 

 

 

 

이만 총총

댓글