Last active
November 2, 2022 00:30
-
-
Save dfop02/7d20c2d11839e3f8ba7f9bf7684177db to your computer and use it in GitHub Desktop.
Discord Bot that copy a message reacted n times by specific emoji then paste into other channel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import discord | |
from discord.utils import get | |
from dotenv import load_dotenv | |
load_dotenv() | |
# Bot Token | |
DISCORD_TOKEN = os.getenv('DISCORD_TOKEN') | |
# Channel to listen (full name) | |
CHANNEL_LISTEN = os.getenv('CHANNEL_LISTEN') | |
# Channel to paste the message (full name) | |
CHANNEL_SAVE = os.getenv('CHANNEL_SAVE') | |
bot = discord.Client() | |
@bot.event | |
async def on_ready(): | |
print(f'{bot.user} has connected to Discord!') | |
async def report(message): | |
# Get the channel by name | |
channel = get(bot.get_all_channels(), name=CHANNEL_SAVE, type=discord.ChannelType.text) | |
# Finally send the message into channel setting the user and message | |
await channel.send(f'By: {message.author.name}\n{message.content}') | |
@bot.event | |
async def on_message(message): | |
emoji_name = 'sifoda' | |
# Validates the user, chat and emoji | |
def check(reaction, user): | |
geral_chat_id = get(bot.get_all_channels(), name=CHANNEL_LISTEN).id | |
return message.author == user and message.channel.id == geral_chat_id and str(reaction.emoji.name) == emoji_name | |
# The while is because you need keep tracking for new reactions | |
while True: | |
# If someone react to a new message on channel you setted | |
res = await bot.wait_for('reaction_add', check=check) | |
if res: | |
# get the reaction and separate emojis for the choosen one | |
reaction, user = res | |
emoji = [x for x in message.reactions if str(x.emoji.name) == emoji_name] | |
# if there is more or equal than N emoji | |
if emoji[0].count >= 5: | |
# send the message to other channel | |
await report(message) | |
bot.run(DISCORD_TOKEN) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment