Compare commits
No commits in common. "0736e8f2114000e9bec44f475929caeae7cc124d" and "0c3168627ffad362e36e7626b6107f748c103188" have entirely different histories.
0736e8f211
...
0c3168627f
|
|
@ -1 +0,0 @@
|
|||
node_modules
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
FROM node:lts-alpine
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
RUN npm install
|
||||
COPY . .
|
||||
CMD [ "node", "app.js" ]
|
||||
88
app.js
88
app.js
|
|
@ -1,9 +1,7 @@
|
|||
import dotenv from 'dotenv';
|
||||
import * as util from './utils.js'
|
||||
import { REST, Routes } from 'discord.js';
|
||||
import { Client, GatewayIntentBits } from 'discord.js';
|
||||
import { EmbedBuilder } from 'discord.js';
|
||||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js';
|
||||
import { Client, GatewayIntentBits, EmbedBuilder } from 'discord.js';
|
||||
|
||||
dotenv.config();
|
||||
const TOKEN = process.env.TOKEN;
|
||||
|
|
@ -28,28 +26,13 @@ const CLIENT_ID = process.env.CLI_ID;
|
|||
// console.error(error);
|
||||
// }
|
||||
|
||||
const roles = {
|
||||
'❤️': '1221079597962104872',
|
||||
'🧡': '1221091257665720360',
|
||||
'💛': '1221091363475423374',
|
||||
'💚': '1221080091371765812',
|
||||
'🩵': '1221091149796610088',
|
||||
'💙': '1221080047469858826',
|
||||
'💜': '1221095844288270387',
|
||||
'🔁': 'reset',
|
||||
};
|
||||
let botMessageId = '';
|
||||
|
||||
|
||||
const client = new Client({
|
||||
intents: [
|
||||
const intents = [
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMessages,
|
||||
GatewayIntentBits.MessageContent,
|
||||
GatewayIntentBits.GuildMessageReactions,
|
||||
GatewayIntentBits.GuildMembers, // 역할을 부여하기 위해 필요
|
||||
]
|
||||
});
|
||||
];
|
||||
const client = new Client({ intents: intents });
|
||||
|
||||
|
||||
client.on('ready', () => {
|
||||
console.log(`Logged in as ${client.user.tag}!`);
|
||||
|
|
@ -100,65 +83,4 @@ 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);
|
||||
Loading…
Reference in New Issue