Moving the reaction roles into the cog HelpCommands.py

pull/4/head
sgoudham 4 years ago
parent 7b662adfd9
commit 65cb86fedd

@ -1,6 +1,7 @@
import asyncio
import datetime
import discord
from discord import Embed, Colour
from discord.ext import commands
from discord.ext.commands import command, cooldown, BucketType
@ -11,6 +12,62 @@ class CustomHelp(commands.Cog):
def __init__(self, bot):
self.bot = bot
# Cog listener for enabling roles to be added to users when they react to the embedded message
@commands.Cog.listener()
async def on_raw_reaction_add(self, payload):
# If the message id equals the self roles message
if payload.message_id == 722514840559812649:
# Print out the emoji name
print(payload.emoji.name)
# Find a role corresponding to the Emoji name.
guild_id = payload.guild_id
# Find the guild Enso and find the role of the emoji that has been reacted to
guild = discord.utils.find(lambda g: g.id == guild_id, self.bot.guilds)
role = discord.utils.find(lambda r: r.name == payload.emoji.name, guild.roles)
# if the role does exist
if role is not None:
# Print to me that the role was found and display the id of the role
print(role.name + " was found!")
print(role.id)
# Find the member who had reacted to the emoji
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
# Add the role to the member
await member.add_roles(role)
# Print to me that the role has been added
print("done")
# Cog listener for enabling roles to be removed from users when they unreact to the embedded messaged
@commands.Cog.listener()
async def on_raw_reaction_remove(self, payload):
# If the message id equals the self roles message
if payload.message_id == 722514840559812649:
# Print out the emoji name
print(payload.emoji.name)
# Get the server id
guild_id = payload.guild_id
# Find the guild Enso and find the role of the emoji that has been unreacted to
guild = discord.utils.find(lambda g: g.id == guild_id, self.bot.guilds)
role = discord.utils.find(lambda r: r.name == payload.emoji.name, guild.roles)
# if the role does exist
if role is not None:
# Find the member that has the role which the emoji is connected to
member = discord.utils.find(lambda m: m.id == payload.user_id, guild.members)
# Remove the role from the member
await member.remove_roles(role)
# ~rules command allows for an embed message about the leveled roles and xp system
@command(name="rules", aliases=["Rules"])
@cooldown(1, 5, BucketType.user)
@ -26,9 +83,6 @@ class CustomHelp(commands.Cog):
enso_icon = self.bot.user.avatar_url
enso_name = self.bot.user.display_name
# Surround with try/except to catch any exceptions that may occur
try:
# Set up embed to list all the rules within the server
embed = Embed(title="```(っ◔◡◔)っ Ensō Rules```",
colour=Colour(0xFF69B4),
@ -137,9 +191,6 @@ class CustomHelp(commands.Cog):
# Delete the message
await message.delete()
except Exception as e:
print(e)
# ~roles command allows for an embed message about roles
@command(name="roles", aliases=["Roles"])
async def roles(self, ctx):
@ -155,9 +206,6 @@ class CustomHelp(commands.Cog):
# Get the url of the leveled roles image
roles_image = "https://media.discordapp.net/attachments/669812887564320769/717149671771996180/unknown.png"
# Surround with try/except to catch any exceptions that may occur
try:
# Setting up embedded message about the leveled roles system within the server
embed = Embed(title="```So you wanna know how the leveled roles system works huh?```",
colour=Colour(0xFF69B4),
@ -191,14 +239,12 @@ class CustomHelp(commands.Cog):
# Delete the message
await message.delete()
except Exception as e:
print(e)
# Send a message to the channel that Enso~Chan has dm'ed them!
def helpDm():
hamothyID = '<@&715412394968350756>'
# Returning F String to send to the User
return f"I've just pinged your dms UwU! <a:huh:676195228872474643> <a:huh:676195228872474643>" \
f"\nPlease ping my owner {hamothyID} for any issues/questions you have!"

Loading…
Cancel
Save