Travisᵐᵒᵐᵒ⨳ᵀᴬ
Travisᵐᵒᵐᵒ⨳ᵀᴬ
DIAdiscord.js - Imagine an app
Created by Travisᵐᵒᵐᵒ⨳ᵀᴬ on 11/15/2024 in #djs-questions
Locate (multiple) images in post and repost to different channel
Thanks for the help @Qjuh
5 replies
DIAdiscord.js - Imagine an app
Created by Travisᵐᵒᵐᵒ⨳ᵀᴬ on 11/15/2024 in #djs-questions
Locate (multiple) images in post and repost to different channel
const { Client, IntentsBitField, MessageCollector, Collection } = require('discord.js');

const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
],
});

client.on('ready', (c) => {
console.log(`✅ ${c.user.username} is searching for profit posts...`)
});

// Update with proper channel ID
const sourceChannelId = ('1306013045021212724');

// Update with proper channel ID
const targetChannelId = ('607218826983243779');

// Send Message
client.on('messageCreate', (message) => {

// Prevent bot from messaging itself, looping, and sending reply to incorrect channel
if (message.author.bot || message.channelId !== sourceChannelId) return;

// Print data to terminal
console.log(message);

// Update with proper role ID
const roleId = ('1073347163570045031');

// Filter images that start with 'image'
const imageAttachments = message.attachments.filter(attachment => attachment.contentType && attachment.contentType.startsWith('image/'));

// Map to attachment.url
const attachmentURLs = imageAttachments.map(attachment => attachment.url);
const allImageURLs = [...attachmentURLs];

// Validation
const targetChannel = client.channels.cache.get(targetChannelId);
const discordId = (message.author.id);

if (allImageURLs.length) {
console.log('Located profit post URL(s):', [allImageURLs]);
targetChannel.send({
content: `<@&${roleId}> profit post from <@${discordId}>`,
files: [...attachmentURLs]});
}
});
const { Client, IntentsBitField, MessageCollector, Collection } = require('discord.js');

const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
],
});

client.on('ready', (c) => {
console.log(`✅ ${c.user.username} is searching for profit posts...`)
});

// Update with proper channel ID
const sourceChannelId = ('1306013045021212724');

// Update with proper channel ID
const targetChannelId = ('607218826983243779');

// Send Message
client.on('messageCreate', (message) => {

// Prevent bot from messaging itself, looping, and sending reply to incorrect channel
if (message.author.bot || message.channelId !== sourceChannelId) return;

// Print data to terminal
console.log(message);

// Update with proper role ID
const roleId = ('1073347163570045031');

// Filter images that start with 'image'
const imageAttachments = message.attachments.filter(attachment => attachment.contentType && attachment.contentType.startsWith('image/'));

// Map to attachment.url
const attachmentURLs = imageAttachments.map(attachment => attachment.url);
const allImageURLs = [...attachmentURLs];

// Validation
const targetChannel = client.channels.cache.get(targetChannelId);
const discordId = (message.author.id);

if (allImageURLs.length) {
console.log('Located profit post URL(s):', [allImageURLs]);
targetChannel.send({
content: `<@&${roleId}> profit post from <@${discordId}>`,
files: [...attachmentURLs]});
}
});
5 replies