<gh_stars>0
#################################################
# Program:  CommissionerBot
# Version:  0.2.0
# Version Date:  02/13/2021
# Author:  <NAME>
# Date:  11/14/2020
# Contributor(s):
# Parameters:
# This bot will auto assign roles when a user reacts to a message with an emoji
# Console output will display the role and the username it is assigned to
#################################################

#################################################
# Import dependencies
#################################################
import os
import discord
from dotenv import load_dotenv
from datetime import datetime

load_dotenv()
client = discord.Client()

#################################################
# Pull Discord token, guild, channel, and message
# IDs from .env file
#################################################
TOKEN = os.getenv("DISCORD_TOKEN")
GUILD = os.getenv("DISCORD_GUILD")
MESSAGE = int(os.getenv("MESSAGE_ID"))
CHANNEL = int(os.getenv("CHANNEL_ID"))


#################################################
# Test and confirm bot has connected to Discord
# As well as date and time of event
#################################################
crono_now = datetime.now()
crono_log = crono_now.strftime("%m/%d/%Y %H:%M:%S")


@client.event
async def on_ready():
    for guild in client.guilds:
        if guild.name == GUILD:
            print(
                f"{crono_log}: {client.user} has connected to Discord!\n"
                f"{client.user} is connected to the following guild(s):\n"
                f"{guild.name} (id: {guild.id})\n"
            )
            break


#################################################
# When member selects emoji they will be given
# a role.
#################################################
@client.event
async def on_raw_reaction_add(payload):
    message_id = payload.message_id
    if message_id == MESSAGE:
        guild_id = payload.guild_id
        guild = discord.utils.find(lambda g: g.id == guild_id, client.guilds)

        if payload.emoji.name == 'fry':
            role = discord.utils.get(guild.roles, name='Memes')
            print(f"{role} selected")
        elif payload.emoji.name == 'beaker':
            role = discord.utils.get(guild.roles, name='Scientist')
            print(f"{role} selected")
        elif payload.emoji.name == 'philosophy':
            role = discord.utils.get(guild.roles, name='Philosopher')
            print(f'{role} selected')
        elif payload.emoji.name == 'mind':
            role = discord.utils.get(guild.roles, name='Character Building')
            print(f'{role} selected')
        elif payload.emoji.name == 'd20':
            role = discord.utils.get(guild.roles, name='Table Top')
            print(f'{role} selected')
        elif payload.emoji.name == 'pawn':
            role = discord.utils.get(guild.roles, name='Chess Master')
            print(f'{role} selected')
        elif payload.emoji.name == 'dice':
            role = discord.utils.get(guild.roles, name='Board Games')
            print(f'{role} selected')
        elif payload.emoji.name == 'minecraft':
            role = discord.utils.get(guild.roles, name='Minecraft')
            print(f'{role} selected')
        elif payload.emoji.name == 'controller':
            role = discord.utils.get(guild.roles, name='Console Gamer')
            print(f'{role} selected')
        else:
            role = discord.utils.get(guild.roles, name=payload.emoji.name)

        if role is not None:
            member = payload.member
            await member.add_roles(role)
            print(f"{role} assigned to {member}\n")
        else:
            print("No role assigned.")


client.run(TOKEN)

#################################################
# Program:  CommissionerBot
# Version:  0.2.0
# Version Date:  02/13/2021
# Author:  <NAME>
# Date:  11/14/2020
# Contributor(s):
# Parameters:
# This bot will auto assign roles when a user reacts to a message with an emoji
# Console output will display the role and the username it is assigned to
#################################################

#################################################
# Import dependencies
#################################################
import os
import discord
from dotenv import load_dotenv
from datetime import datetime

load_dotenv()
client = discord.Client()

#################################################
# Pull Discord token, guild, channel, and message
# IDs from .env file
#################################################
TOKEN = os.getenv("DISCORD_TOKEN")
GUILD = os.getenv("DISCORD_GUILD")
MESSAGE = int(os.getenv("MESSAGE_ID"))
CHANNEL = int(os.getenv("CHANNEL_ID"))


#################################################
# Test and confirm bot has connected to Discord
# As well as date and time of event
#################################################
crono_now = datetime.now()
crono_log = crono_now.strftime("%m/%d/%Y %H:%M:%S")


@client.event
async def on_ready():
    for guild in client.guilds:
        if guild.name == GUILD:
            print(
                f"{crono_log}: {client.user} has connected to Discord!\n"
                f"{client.user} is connected to the following guild(s):\n"
                f"{guild.name} (id: {guild.id})\n"
            )
            break


#################################################
# When member selects emoji they will be given
# a role.
#################################################
@client.event
async def on_raw_reaction_add(payload):
    message_id = payload.message_id
    if message_id == MESSAGE:
        guild_id = payload.guild_id
        guild = discord.utils.find(lambda g: g.id == guild_id, client.guilds)

        if payload.emoji.name == 'fry':
            role = discord.utils.get(guild.roles, name='Memes')
            print(f"{role} selected")
        elif payload.emoji.name == 'beaker':
            role = discord.utils.get(guild.roles, name='Scientist')
            print(f"{role} selected")
        elif payload.emoji.name == 'philosophy':
            role = discord.utils.get(guild.roles, name='Philosopher')
            print(f'{role} selected')
        elif payload.emoji.name == 'mind':
            role = discord.utils.get(guild.roles, name='Character Building')
            print(f'{role} selected')
        elif payload.emoji.name == 'd20':
            role = discord.utils.get(guild.roles, name='Table Top')
            print(f'{role} selected')
        elif payload.emoji.name == 'pawn':
            role = discord.utils.get(guild.roles, name='Chess Master')
            print(f'{role} selected')
        elif payload.emoji.name == 'dice':
            role = discord.utils.get(guild.roles, name='Board Games')
            print(f'{role} selected')
        elif payload.emoji.name == 'minecraft':
            role = discord.utils.get(guild.roles, name='Minecraft')
            print(f'{role} selected')
        elif payload.emoji.name == 'controller':
            role = discord.utils.get(guild.roles, name='Console Gamer')
            print(f'{role} selected')
        else:
            role = discord.utils.get(guild.roles, name=payload.emoji.name)

        if role is not None:
            member = payload.member
            await member.add_roles(role)
            print(f"{role} assigned to {member}\n")
        else:
            print("No role assigned.")


client.run(TOKEN)
################################################# # Program:  CommissionerBot # Version:  0.2.0 # Version Date:  02/13/2021 # Author:  <NAME> # Date:  11/14/2020 # Contributor(s): # Parameters: # This bot will auto assign roles when a user reacts to a message with an emoji # Console output will display the role and the username it is assigned to ################################################# ################################################# # Import dependencies ################################################# ################################################# # Pull Discord token, guild, channel, and message # IDs from .env file ################################################# ################################################# # Test and confirm bot has connected to Discord # As well as date and time of event ################################################# ################################################# # When member selects emoji they will be given # a role. #################################################