9
9
10
10
load_dotenv ()
11
11
TOKEN = os .getenv ('DISCORD_TOKEN' )
12
+ VERIFICATION_MESSAGE_ID = 820693368182013952
13
+ VERIFICATION_ROLE_ID = 820690464100581377
12
14
13
15
client = discord .Client ()
14
16
30
32
channel_ids = []
31
33
trivia_channel_ids = []
32
34
events_channel_ids = []
35
+ roles_channel_ids = []
33
36
34
37
35
38
@aiocron .crontab ('15 5 * * *' )
@@ -60,6 +63,34 @@ async def cronjob4():
60
63
await client .get_channel (channel_id ).send ("Zapraszamy na kanał głosowy Relaks na wspólną kawę! ☕" )
61
64
62
65
66
+
67
+ def compare_emojis (reaction_emoji ):
68
+ return reaction_emoji .name == "🔑"
69
+
70
+ @client .event
71
+ async def on_raw_reaction_add (reaction ):
72
+ print ("tutaj" )
73
+ print (reaction .emoji .name )
74
+ if reaction .message_id != 820693368182013952 :
75
+ return
76
+ if compare_emojis (reaction .emoji ):
77
+ verification_role = discord .utils .get (reaction .member .guild .roles , id = VERIFICATION_ROLE_ID )
78
+ await reaction .member .add_roles (verification_role )
79
+ print ("role added" )
80
+
81
+ @client .event
82
+ async def on_raw_reaction_remove (reaction ):
83
+ if reaction .message_id != 820693368182013952 :
84
+ return
85
+ if compare_emojis (reaction .emoji ):
86
+ # guild_id + user_id -> member.id / member object
87
+ guild = client .get_guild (reaction .guild_id )
88
+ member = discord .utils .get (guild .members , id = reaction .user_id )
89
+ # member = client.get_member(reaction.user_id)
90
+ verification_role = discord .utils .get (guild .roles , id = VERIFICATION_ROLE_ID )
91
+ await member .remove_roles (verification_role )
92
+ print ("role removed" )
93
+
63
94
@client .event
64
95
async def on_ready ():
65
96
global channel_ids
@@ -73,6 +104,16 @@ async def on_ready():
73
104
trivia_channel_ids .append (channel .id )
74
105
if 'wydarzenia' in channel .name :
75
106
events_channel_ids .append (channel .id )
107
+ if 'role' in channel .name :
108
+ roles_channel_ids .append (channel .id )
109
+ try :
110
+ msg = await channel .fetch_message (VERIFICATION_MESSAGE_ID )
111
+ print (msg .content )
112
+ except discord .NotFound :
113
+ # TODO zmień na coś lepszego
114
+ print ("Wiadomość weryfikacyjna o tym ID nie istnieje" )
115
+ # await client.get_channel(channel.id).send("bot is online")
116
+
76
117
77
118
78
119
client .run (TOKEN )
0 commit comments