-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
73 lines (60 loc) · 2.12 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require("dotenv").config();
const express = require("express");
const { Client, GatewayIntentBits, EmbedBuilder } = require("discord.js");
const client = require("./config/discordClient");
const app = express();
const PORT = process.env.PORT || 3000;
let sourceChannelId = null;
let targetChannelId = null;
client.once("ready", () => {
console.log("Bot is ready!");
});
client.on("interactionCreate", async (interaction) => {
if (!interaction.isCommand()) return;
const { commandName, options } = interaction;
if (commandName === "configure") {
sourceChannelId = options.getChannel("source").id;
targetChannelId = options.getChannel("target").id;
await interaction.reply(
`Source channel set to <#${sourceChannelId}> and target channel set to <#${targetChannelId}>`
);
}
});
client.on("messageCreate", async (message) => {
if (message.author.bot || message.channel.id !== sourceChannelId) return;
const containsKeyword = process.env.KEYWORDS.split(",").some((keyword) =>
message.content.toLowerCase().includes(keyword.toLowerCase())
);
if (containsKeyword) {
const targetChannel = client.channels.cache.get(targetChannelId);
if (!targetChannel) {
console.error("Target channel not found");
return;
}
const attachment = message.attachments.first();
if (attachment) {
const embed = new EmbedBuilder()
.setColor("#0099ff")
.setTitle(
message.content.length > 100
? message.content.substring(0, 97) + "..."
: message.content
)
.setURL(message.url)
.setDescription(`By: <@${message.author.id}>`)
.setImage(attachment.url)
.setTimestamp()
.setThumbnail(message.author.displayAvatarURL({ dynamic: true }));
try {
await targetChannel.send({ embeds: [embed] });
console.log("Message successfully forwarded to target channel");
} catch (error) {
console.error("Error sending message to target channel:", error);
}
}
}
});
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
client.login(process.env.DISCORD_TOKEN);