diff --git a/commands/joinrole.py b/commands/joinrole.py new file mode 100644 index 0000000..6b84049 --- /dev/null +++ b/commands/joinrole.py @@ -0,0 +1,53 @@ +import discord, pymongo, os +from discord.ext import commands + +from dotenv import load_dotenv +load_dotenv() + +def is_enabled(self): + client = pymongo.MongoClient(os.getenv("mongo_url")) + db = client.servers + coll = db.settings + + if coll.find_one({"_id": {"guild_id": self.guild.id, "commands":"joinrole"}}): + command = coll.find_one({"_id": {"guild_id": self.guild.id, "commands":"joinrole"}}) + command_enabled = command["enabled"] # True or False + if command_enabled: + return True + else: + return False + else: + return True + +class joinrole(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.Cog.listener() + async def on_ready(self): + print("Joinrole Online") + + @commands.hybrid_command(name="joinrole", description="Set the joinrole") + @commands.check(is_enabled) + @commands.has_permissions(manage_roles=True) + async def joinrole(self, ctx, role:discord.Role): + client = pymongo.MongoClient(os.getenv("mongo_url")) + db = client.servers + coll = db.roles + + coll.update_one({"_id": {"guild_id": ctx.guild.id, "commands":"joinrole"}}, {"$set": {"joinrole": role.id}}) + await ctx.send(f"Set the joinrole to {role.mention}!") + + @commands.Cog.listener() + async def on_member_join(self, member): + client = pymongo.MongoClient(os.getenv("mongo_url")) + db = client.servers + coll = db.roles + + joinrole = coll.find_one({"_id": {"guild_id": member.guild.id, "commands":"joinrole"}}) + if joinrole: + role = member.guild.get_role(joinrole["joinrole"]) + await member.add_roles(role) + +async def setup(bot): + await bot.add_cog(joinrole(bot)) \ No newline at end of file diff --git a/commands/redeem.py b/commands/redeem.py index 67b5eeb..47079e3 100644 --- a/commands/redeem.py +++ b/commands/redeem.py @@ -9,8 +9,8 @@ def is_enabled(self): db = client.servers coll = db.settings - if coll.find_one({"_id": {"guild_id": self.guild.id, "commands":"ticket"}}): - command = coll.find_one({"_id": {"guild_id": self.guild.id, "commands":"ticket"}}) + if coll.find_one({"_id": {"guild_id": self.guild.id, "commands":"redeem"}}): + command = coll.find_one({"_id": {"guild_id": self.guild.id, "commands":"redeem"}}) command_enabled = command["enabled"] # True or False if command_enabled: return True diff --git a/commands/store.py b/commands/store.py index d8c88bf..ea5b0a5 100644 --- a/commands/store.py +++ b/commands/store.py @@ -12,8 +12,8 @@ def is_enabled(self): db = client.servers coll = db.settings - if coll.find_one({"_id": {"guild_id": self.guild.id, "commands":"ticket"}}): - command = coll.find_one({"_id": {"guild_id": self.guild.id, "commands":"ticket"}}) + if coll.find_one({"_id": {"guild_id": self.guild.id, "commands":"store"}}): + command = coll.find_one({"_id": {"guild_id": self.guild.id, "commands":"store"}}) command_enabled = command["enabled"] # True or False if command_enabled: return True