디스코드 봇 질문
-
게시물 수정 , 삭제는 로그인 필요
const Discord = require('discord.js');
const client = new Discord.Client();
const keepAilve = require('./server.js')
const quiz = require("./quiz.json");
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
const convertEmoji = (who) => {
if(who === "가위"){
return "✌️";
}
else if(who === "바위"){
return "";
}
else if(who === "보"){
return "✋";
}
}
client.on('message', msg => {
if (msg.content === '$하랑이는') {
msg.reply('일베련');
}
else if (msg.content == '$동언이는'){
msg.reply('일베대장');
}
else if (msg.content == '$래지후는'){
msg.reply('멍텅구리');
}
else if (msg.content == '$씨바라'){
msg.reply('<- 이년 없음 ㅋㅋ');
}
else if (msg.content == '$우짱아'){
msg.reply('무지개 반사');
}
if (msg.content === "$프로필") {
const embed = new Discord.MessageEmbed()
.setAuthor("수까봇 :robot:", "https://cdn.discordapp.com/attachments/746683143754481696/952435464831381514/251664214c086b9b.png")
.setTitle("수까봇 프로필")
.setColor(0x00D8FF)
.setDescription("안녕! 수까봇이야. 나를 소개할게! :raised_hands:")
.setThumbnail("https://cdn.discordapp.com/attachments/746683143754481696/952435464831381514/251664214c086b9b.png")
.addFields(
{name: "취미", value: "대답하기:woozy_face:", inline: true},
{name: "특기", value: "로봇:electric_plug:", inline: true},
{name: "혈액형", value: "인형", inline: true},
{name: "사는곳", value: "컴퓨터:computer:", inline: true},
{name: "좋아하는것", value: "전기⚡️", inline: true},
{name: "싫어하는것", value: "물:droplet:", inline: true}
)
.setImage("https://cdn.discordapp.com/attachments/746683143754481696/952435464831381514/251664214c086b9b.png")
.setTimestamp(new Date())
.setFooter("반가워!:heart_eyes:","https://cdn.discordapp.com/attachments/746683143754481696/952435464831381514/251664214c086b9b.png")
msg.channel.send(embed);
}
client.on("message", (message) => {
if(message.author.bot) return;
if(message.author.id === client.user.id) return;
if(message.content === "$퀴즈") {
const item = quiz[Math.floor(Math.random() * quiz.length)];
const limit = 3; // 제한시간
const filter = (response) => {
console.log(item.answer.some((answer) => answer === response.content));
return item.answer.some((answer) => answer === response.content);
}
message.channel.send(`${item.question} (제한시간 : ${limit} 초)`)
.then(() => {
message.channel.awaitMessages(filter, { max: 1, time: limit * 1000})
.then((collected) => {
message.channel.send(`${collected.first().author} 정답!`);
})
.catch((err) => {
message.channel.send("제한시간이 지났버렷어")
})
})
}
})
client.on("message", (message) => {
if(message.content.substring(0,3) === "$투표")
{
const description = message.content.substring(4,16);
const embed = new Discord.MessageEmbed()
.setTitle("투표")
.setDescription(description)
.setColor("RED");
message.channel.send(embed)
.then((msg) => {
msg.react("")
msg.react("")
});
}
})
if(msg.content === "가위" || msg.content === "바위" || msg.content === "보") {
const human = msg.content;
const list = ["가위", "바위", "보"];
const random = Math.floor(Math.random() * 3);
const bot = list[random];
let winner = "너";
if(human === bot) {
winner = "비김";
}
else {
human === "가위" ? (winner = bot === "바위" ? "나" : "너") : "";
human === "바위" ? (winner = bot === "보" ? "나" : "너") : "";
human === "보" ? (winner = bot === "가위" ? "나" : "너") : "";
}
const result =
`
너 : ${convertEmoji(human)} vs 봇 : ${convertEmoji(bot)}
${winner === "비김" ? "악! 비겼어" : winner + "의 승리야!"}
`
msg.reply(result);
}
});
keepAilve()
client.login(process.env.TOKEN);
이렇게 코드를 짯는데 $투표랑 $퀴즈 하면 중복으로 메세지가 계속 나오는데 해결책이 있나요?
#디스코드 봇 #디스코드 봇 추가 #디스코드 봇 만들기 #디스코드 봇 추천 #디스코드 봇 만들기 파이썬 #디스코드 봇 추가 사이트 #디스코드 봇 초대 #디스코드 봇 토큰 #디스코드 봇 호스팅 #디스코드 봇 애플리케이션이 응답하지 않았어요