-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
64 lines (51 loc) · 2.02 KB
/
Copy pathindex.js
File metadata and controls
64 lines (51 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require('dotenv').config();
const { Client, GatewayIntentBits, EmbedBuilder } = require('discord.js');
const DISCORD_TOKEN = process.env.DISCORD_TOKEN;
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});
// Regex to find: discord.com/channels/GuildID/ChannelID/MessageID
const linkRegex = /https:\/\/discord\.com\/channels\/(\d+)\/(\d+)\/(\d+)/;
client.on('messageCreate', async (message) => {
// Ignore bots to prevent infinite loops
if (message.author.bot) return;
const match = message.content.match(linkRegex);
if (!match) return;
const [_, guildId, channelId, messageId] = match;
try {
// 1. Fetch the channel where the linked message lives
const channel = await client.channels.fetch(channelId);
if (!channel) return;
// 2. Fetch the specific message
const targetMsg = await channel.messages.fetch(messageId);
// 3. Construct the Embed
const embed = new EmbedBuilder()
.setAuthor({
name: targetMsg.author.tag,
iconURL: targetMsg.author.displayAvatarURL()
})
.setDescription(targetMsg.content || "_[No text content]_")
.setColor('#5865F2')
.setTimestamp(targetMsg.createdAt)
.setFooter({ text: `Quoted from #${channel.name}` });
// If the original message had an image, add it to the embed
const image = targetMsg.attachments.first();
if (image) embed.setImage(image.url);
// 4. Send the embed to the current channel
await message.reply({
embeds: [embed],
allowedMentions: { repliedUser: false }
});
} catch (error) {
console.error('Could not fetch message:', error);
// Usually fails if the bot isn't in that server or channel
}
});
client.once("ready", async () => {
console.log(`Logged in as ${client.user.tag}`);
});
client.login(DISCORD_TOKEN);