-
Notifications
You must be signed in to change notification settings - Fork 17
/
main.py
101 lines (77 loc) · 2.9 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from config import Config
import discord
from discord.ext import commands
prefix = Config.prefix
token = Config.bot_token
bot = commands.Bot(command_prefix=prefix, intents=discord.Intents.all())
bot.setup = False
bot.role_name = Config.role_name
bot.message_id = Config.message_id
bot.channel_id = Config.channel_id
@bot.event
async def on_ready():
print("Logged in as "+bot.user.name)
@bot.command()
async def setup(ctx):
try:
message_id = int(bot.message_id)
except ValueError:
return await ctx.send("Invalid Message ID passed")
except Exception as e:
raise e
try:
channel_id = int(bot.channel_id)
except ValueError:
return await ctx.send("Invalid Channel ID passed")
except Exception as e:
raise e
channel = bot.get_channel(channel_id)
if channel is None:
return await ctx.send("Channel Not Found")
message = await channel.fetch_message(message_id)
if message is None:
return await ctx.send("Message Not Found")
await message.add_reaction("✅")
await ctx.send("Setup Successful")
bot.setup = True
@bot.event
async def on_raw_reaction_add(payload):
if bot.setup != True:
return print(f"Bot is not setuped\nType {prefix}setup to setup the bot")
if payload.message_id == int(bot.message_id):
if str(payload.emoji) == "✅":
guild = bot.get_guild(payload.guild_id)
if guild is None:
return print("Guild Not Found\nTerminating Process")
try:
role = discord.utils.get(guild.roles, name=bot.role_name)
except:
return print("Role Not Found\nTerminating Process")
member = guild.get_member(payload.user_id)
if member is None:
return
try:
await member.add_roles(role)
except Exception as e:
raise e
@bot.event
async def on_raw_reaction_remove(payload):
if bot.setup != True:
return print(f"Bot is not setuped\nType {prefix}setup to setup the bot")
if payload.message_id == int(bot.message_id):
if str(payload.emoji) == "✅":
guild = bot.get_guild(payload.guild_id)
if guild is None:
return print("Guild Not Found\nTerminating Process")
try:
role = discord.utils.get(guild.roles, name=bot.role_name)
except:
return print("Role Not Found\nTerminating Process")
member = guild.get_member(payload.user_id)
if member is None:
return
try:
await member.remove_roles(role)
except Exception as e:
raise e
bot.run(token)