MysteryPancake / Discord-Reposter

Bot for reposting Discord messages (work in progress)
MIT License
92 stars 121 forks source link

Is it possible to make it only repost if a certain message has 'x' amount of 'reacts'? #21

Open FlowerKid opened 4 years ago

FlowerKid commented 4 years ago

I have been looking for a bot that can repost any post with an image from a public text channel to a private text channel (same server) only when the message reaches 'x' amount of reacts.

The private channel will act as a 'featured posts' channel. So only posts that are popular in the public channel with 'x' amount of reacts are posted into the private channel. any help appreciated

MysteryPancake commented 4 years ago

I'm not sure if this bot would be the best option for this task - It is mainly designed to repost a bunch of messages at once rather than just a specific message under certain conditions.

I think it would be easier to use an independent bot, as most of the reposting functionality isn't required for this type of task.

If you wish to write this bot using Discord.js, I think this would best be done by monitoring the messageReactionAdd event.

I wrote an example bot below which I hope will work for the requirements: <SECRET_BOT_TOKEN> = bot token publicChannelID = public channel's ID privateChannelID = private channel's ID emoji = emoji which will be reacted x = number of reactions

"use strict";

console.log("LOADING LIBRARIES...");

const Discord = require("discord.js");
const client = new Discord.Client();

client.login("<SECRET_BOT_TOKEN>").catch(console.error);

const publicChannelID = "123456789123456789";
const privateChannelID = "987654321987654321";
const emoji = "✅";
const x = 2;

let publicChannel;
let privateChannel;

client.on("ready", function() {
    console.log("READY FOR ACTION!");
    publicChannel = client.channels.get(publicChannelID);
    privateChannel = client.channels.get(privateChannelID);
});

function hasImage(attachments) {
    for (let i = 0; i < attachments.length; i++) {
        if (attachments[i].width || attachments[i].height) {
            return true;
        }
    }
    return false;
}

client.on("messageReactionAdd", function(messageReaction) {
    const message = messageReaction.message;
    if (message.channel === publicChannel && hasImage(message.attachments) && messageReaction.emoji.toString() === emoji && messageReaction.count === x) {
        privateChannel.send(message).catch(console.error);
    }
});
FlowerKid commented 4 years ago

Thank you for your response!

I wasn't entirely sure if the nature of your Discord-Reposter would suit what I needed, but after searching a couple days of internet it's the very closest I could find.

I'm just getting started with my server since a few people in my community have been asking so your fast response is amazing, i'll give what you have sent a shot and honestly thank you very much :)