86 lines
2.6 KiB
JavaScript
86 lines
2.6 KiB
JavaScript
import dotenv from 'dotenv';
|
|
import * as util from './utils.js'
|
|
import { REST, Routes } from 'discord.js';
|
|
import { Client, GatewayIntentBits, EmbedBuilder } from 'discord.js';
|
|
|
|
dotenv.config();
|
|
const TOKEN = process.env.TOKEN;
|
|
const CLIENT_ID = process.env.CLI_ID;
|
|
|
|
// const commands = [
|
|
// {
|
|
// name: 'ping',
|
|
// description: 'Replies with Pong!',
|
|
// },
|
|
// ];
|
|
|
|
// const rest = new REST({ version: '10' }).setToken(TOKEN);
|
|
|
|
// try {
|
|
// console.log('Started refreshing application (/) commands.');
|
|
|
|
// await rest.put(Routes.applicationCommands(CLIENT_ID), { body: commands });
|
|
|
|
// console.log('Successfully reloaded application (/) commands.');
|
|
// } catch (error) {
|
|
// console.error(error);
|
|
// }
|
|
|
|
const intents = [
|
|
GatewayIntentBits.Guilds,
|
|
GatewayIntentBits.GuildMessages,
|
|
GatewayIntentBits.MessageContent,
|
|
];
|
|
const client = new Client({ intents: intents });
|
|
|
|
|
|
client.on('ready', () => {
|
|
console.log(`Logged in as ${client.user.tag}!`);
|
|
});
|
|
|
|
|
|
client.on('interactionCreate', async interaction => {
|
|
if (!interaction.isChatInputCommand()) return;
|
|
|
|
if (interaction.commandName === 'ping') {
|
|
await interaction.reply('Pong!');
|
|
}
|
|
});
|
|
|
|
|
|
client.on('messageCreate', async message => {
|
|
const urlPattern = /https?:\/\/(www\.)?gall\.dcinside\.com\/[^\s]*/g;
|
|
const urls = message.content.match(urlPattern);
|
|
|
|
if (urls && urls.length > 0) {
|
|
const metaData = await util.getMetaData(urls[0]); // 첫 번째 URL의 메타데이터를 추출합니다.
|
|
|
|
const embed = new EmbedBuilder()
|
|
.setColor(0x0099FF)
|
|
.setTitle(metaData.title)
|
|
.setURL(urls[0])
|
|
// .setAuthor({ name: 'Some name', iconURL: 'https://i.imgur.com/AfFp7pu.png', url: 'https://discord.js.org' })
|
|
.setDescription(metaData.description)
|
|
.setImage(metaData.image)
|
|
.setThumbnail(metaData.image)
|
|
// .setThumbnail('https://i.imgur.com/AfFp7pu.png')
|
|
// .addFields(
|
|
// { name: 'Regular field title', value: 'Some value here' },
|
|
// { name: '\u200B', value: '\u200B' },
|
|
// { name: 'Inline field title', value: 'Some value here', inline: true },
|
|
// { name: 'Inline field title', value: 'Some value here', inline: true },
|
|
// )
|
|
// .addFields({ name: '인라인 필드 제목', value: '값', inline: true })
|
|
// .setImage('https://i.imgur.com/AfFp7pu.png')
|
|
// .setTimestamp()
|
|
// .setFooter({ text: 'footer', iconURL: 'https://i.imgur.com/AfFp7pu.png' });
|
|
// if (metaData.image) {
|
|
// console.log(metaData.image);
|
|
// embed.setImage(metaData.image);
|
|
// }
|
|
|
|
message.channel.send({ embeds: [embed] });
|
|
}
|
|
});
|
|
|
|
client.login(TOKEN); |