-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (42 loc) · 1.77 KB
/
index.js
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
import { Client, GatewayIntentBits, TextChannel } from 'discord.js';
import config from './config.json' with { type: "json" };
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});
client.on('messageCreate', (message) => {
if (message.author.bot) return;
const mainChannel = config.channels.find((ch) => ch.channelId == message.channelId);
if (!mainChannel) return;
const forwardingChannelsName = mainChannel.forwardingTo;
const forwardingChannels = client.channels.cache.filter((ch) => ch.isTextBased() && forwardingChannelsName == ch.name);
forwardingChannels.forEach(async (forwardingChannel) => {
if (!forwardingChannel.isTextBased()) return;
const webhooks = await forwardingChannel.fetchWebhooks();
let forwardingWebhook = webhooks.find((wh) => wh.name == 'Forwarding Bot');
if (!forwardingWebhook) {
console.log('Webhook not found, creating...');
const webhook = await forwardingChannel.createWebhook({
name: 'Forwarding Bot'
});
console.log('Webhook created:', webhook);
forwardingWebhook = webhook;
}
const messageContent = message.content;
const messageAttachments = message.attachments.map((attachment) => attachment.url);
const options = {
username: message.author.displayName,
avatarURL: message.author.displayAvatarURL(),
content: messageContent,
files: messageAttachments
};
await forwardingWebhook.send(options);
});
});
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.login(config.token);