● /workbook_user
/workbook_user 명령어는 입력받은 유저가 제작한 문제집의 링크를 연결하는 봇이다.
client.on('messageCreate', (msg) => {
if (msg.content.startsWith('/workbook_user')) {
const num = msg.content.slice('/workbook_user'.length).trim();
msg.reply(`${num}가 만든 문제집 링크: https://www.acmicpc.net/workbook/by/${num}`);
}
});
msg명령어를 받아서 문자열이 /workbook_user로 시작한다면 사용자가 만든 문제집의 링크를 출력한다.
나는 이 기능을 구현하면서 04의 기능인 /workbook과 앞에 문자열이 같아서 우선순위 때문에 틀려서 당황을 했었다.
만약에 명령어의 앞 문자열이 같다면 더 긴 문자열을 상위 조건문에 위치시키면 쉽게 해결된다.
● 실행
'Programming Project > Solved.AC Discord Bot' 카테고리의 다른 글
Discord Bot 만들기 - 06 /problem_sort (0) | 2024.03.06 |
---|---|
Discord Bot 만들기 - 04 /workbook (0) | 2024.03.05 |
Discord Bot 만들기 - 03 /step (0) | 2024.03.02 |
Discord Bot 만들기 - 02 /user (0) | 2024.03.01 |
Discord Bot 만들기 - 01 /problem (0) | 2024.03.01 |