|
|
|
@ -1,7 +1,9 @@
|
|
|
|
import dotenv from 'dotenv';
|
|
|
|
import dotenv from 'dotenv';
|
|
|
|
import * as util from './utils.js'
|
|
|
|
import * as util from './utils.js'
|
|
|
|
import { REST, Routes } from 'discord.js';
|
|
|
|
import { REST, Routes } from 'discord.js';
|
|
|
|
import { Client, GatewayIntentBits, EmbedBuilder } from 'discord.js';
|
|
|
|
import { Client, GatewayIntentBits } from 'discord.js';
|
|
|
|
|
|
|
|
import { EmbedBuilder } from 'discord.js';
|
|
|
|
|
|
|
|
import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js';
|
|
|
|
|
|
|
|
|
|
|
|
dotenv.config();
|
|
|
|
dotenv.config();
|
|
|
|
const TOKEN = process.env.TOKEN;
|
|
|
|
const TOKEN = process.env.TOKEN;
|
|
|
|
@ -26,14 +28,29 @@ const CLIENT_ID = process.env.CLI_ID;
|
|
|
|
// console.error(error);
|
|
|
|
// console.error(error);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
const intents = [
|
|
|
|
const roles = {
|
|
|
|
GatewayIntentBits.Guilds,
|
|
|
|
'❤️': '1221079597962104872',
|
|
|
|
GatewayIntentBits.GuildMessages,
|
|
|
|
'🧡': '1221091257665720360',
|
|
|
|
GatewayIntentBits.MessageContent,
|
|
|
|
'💛': '1221091363475423374',
|
|
|
|
];
|
|
|
|
'💚': '1221080091371765812',
|
|
|
|
const client = new Client({ intents: intents });
|
|
|
|
'🩵': '1221091149796610088',
|
|
|
|
|
|
|
|
'💙': '1221080047469858826',
|
|
|
|
|
|
|
|
'💜': '1221095844288270387',
|
|
|
|
|
|
|
|
'🔁': 'reset',
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
let botMessageId = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const client = new Client({
|
|
|
|
|
|
|
|
intents: [
|
|
|
|
|
|
|
|
GatewayIntentBits.Guilds,
|
|
|
|
|
|
|
|
GatewayIntentBits.GuildMessages,
|
|
|
|
|
|
|
|
GatewayIntentBits.MessageContent,
|
|
|
|
|
|
|
|
GatewayIntentBits.GuildMessageReactions,
|
|
|
|
|
|
|
|
GatewayIntentBits.GuildMembers, // 역할을 부여하기 위해 필요
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
client.on('ready', () => {
|
|
|
|
client.on('ready', () => {
|
|
|
|
console.log(`Logged in as ${client.user.tag}!`);
|
|
|
|
console.log(`Logged in as ${client.user.tag}!`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
@ -56,13 +73,13 @@ client.on('messageCreate', async message => {
|
|
|
|
const metaData = await util.getMetaData(urls[0]); // 첫 번째 URL의 메타데이터를 추출합니다.
|
|
|
|
const metaData = await util.getMetaData(urls[0]); // 첫 번째 URL의 메타데이터를 추출합니다.
|
|
|
|
|
|
|
|
|
|
|
|
const embed = new EmbedBuilder()
|
|
|
|
const embed = new EmbedBuilder()
|
|
|
|
.setColor(0x0099FF)
|
|
|
|
.setColor(0x0099FF)
|
|
|
|
.setTitle(metaData.title)
|
|
|
|
.setTitle(metaData.title)
|
|
|
|
.setURL(urls[0])
|
|
|
|
.setURL(urls[0])
|
|
|
|
// .setAuthor({ name: 'Some name', iconURL: 'https://i.imgur.com/AfFp7pu.png', url: 'https://discord.js.org' })
|
|
|
|
// .setAuthor({ name: 'Some name', iconURL: 'https://i.imgur.com/AfFp7pu.png', url: 'https://discord.js.org' })
|
|
|
|
.setDescription(metaData.description)
|
|
|
|
.setDescription(metaData.description)
|
|
|
|
.setImage(metaData.image)
|
|
|
|
.setImage(metaData.image)
|
|
|
|
.setThumbnail(metaData.image)
|
|
|
|
.setThumbnail(metaData.image)
|
|
|
|
// .setThumbnail('https://i.imgur.com/AfFp7pu.png')
|
|
|
|
// .setThumbnail('https://i.imgur.com/AfFp7pu.png')
|
|
|
|
// .addFields(
|
|
|
|
// .addFields(
|
|
|
|
// { name: 'Regular field title', value: 'Some value here' },
|
|
|
|
// { name: 'Regular field title', value: 'Some value here' },
|
|
|
|
@ -83,4 +100,65 @@ client.on('messageCreate', async message => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.on('messageCreate', async message => {
|
|
|
|
|
|
|
|
const badLang = ['권태웅', '태웅', '웅태'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (badLang.some(word => message.content.includes(word))) {
|
|
|
|
|
|
|
|
const str = `어허 나쁜말 쓰지 마세요`;
|
|
|
|
|
|
|
|
message.channel.send(str);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 'send-reactions' 커맨드를 받았을 때 리액션이 포함된 메시지를 보냄
|
|
|
|
|
|
|
|
client.on('messageCreate', async message => {
|
|
|
|
|
|
|
|
if (message.content === '!색상') {
|
|
|
|
|
|
|
|
const sentMessage = await message.channel.send('색상을 선택하세요.');
|
|
|
|
|
|
|
|
botMessageId = sentMessage.id; // 메시지 ID 저장
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 'roles' 객체에서 이모지 키들을 추출하고, 각 이모지에 대해 리액션 추가
|
|
|
|
|
|
|
|
Object.keys(roles).forEach(async emoji => {
|
|
|
|
|
|
|
|
if (emoji !== '🔁') { // '리셋' 이모지는 마지막에 추가하기 위해 여기서는 제외
|
|
|
|
|
|
|
|
await sentMessage.react(emoji);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
await sentMessage.react('🔁');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 리액션 추가 이벤트 처리
|
|
|
|
|
|
|
|
client.on('messageReactionAdd', async (reaction, user) => {
|
|
|
|
|
|
|
|
if (reaction.message.partial) await reaction.message.fetch();
|
|
|
|
|
|
|
|
if (reaction.partial) await reaction.fetch();
|
|
|
|
|
|
|
|
if (user.bot) return; // 봇의 리액션 무시
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (reaction.message.id === botMessageId) {
|
|
|
|
|
|
|
|
if (reaction.message.author.bot) {
|
|
|
|
|
|
|
|
await reaction.users.remove(user.id); // 리액션 바로 원복
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { emoji } = reaction;
|
|
|
|
|
|
|
|
const member = reaction.message.guild.members.cache.get(user.id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const roleId = roles[emoji.name];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (roleId === 'reset') {
|
|
|
|
|
|
|
|
// 모든 색상 역할 제거를 병렬로 처리
|
|
|
|
|
|
|
|
const removeRolesPromises = Object.values(roles).filter(id => id !== 'reset' && member.roles.cache.has(id)).map(id => member.roles.remove(id));
|
|
|
|
|
|
|
|
await Promise.all(removeRolesPromises);
|
|
|
|
|
|
|
|
} else if (roleId) {
|
|
|
|
|
|
|
|
// 먼저 모든 색상 역할 제거 후 선택한 역할 추가
|
|
|
|
|
|
|
|
const allRoleIds = Object.values(roles).filter(id => id !== 'reset');
|
|
|
|
|
|
|
|
const removeRolesPromises = allRoleIds.filter(id => member.roles.cache.has(id)).map(id => member.roles.remove(id));
|
|
|
|
|
|
|
|
await Promise.all(removeRolesPromises);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const role = reaction.message.guild.roles.cache.get(roleId);
|
|
|
|
|
|
|
|
if (role) {
|
|
|
|
|
|
|
|
await member.roles.add(role);
|
|
|
|
|
|
|
|
console.log(`${user.username}에게 ${role.name}역할이 부여되었습니다.`);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.login(TOKEN);
|
|
|
|
client.login(TOKEN);
|