@@ -22,11 +22,11 @@ def __init__(self, bot):
22
22
def is_verified (self , member ):
23
23
if "✅" in [role .name for role in member .roles ]:
24
24
return True
25
-
25
+
26
26
async def send_wrong_button_message (self , guild , member ):
27
27
button_message = f"""
28
28
Hi there, { member .mention }
29
- you have pressed the wrong button to verify yourself.
29
+ you have pressed the wrong button to verify yourself.
30
30
31
31
Make sure you press the **GREEN** button to verify yourself.
32
32
Please join the server again and try again.
@@ -46,21 +46,21 @@ async def send_wrong_button_message_and_kick(self, interaction: discord.Interact
46
46
await self .send_wrong_button_message (interaction .guild , user )
47
47
await user .kick (reason = "User failed to verify by pressing red button." )
48
48
49
- @discord .ui .button (label = "Verify!" , row = 0 , style = discord .ButtonStyle .red )
49
+ @discord .ui .button (label = "Verify!" , row = 0 , custom_id = "Button_1" , style = discord .ButtonStyle .red )
50
50
async def verify_button_callback_red_1 (self , button : discord .ui .Button , interaction : discord .Interaction ):
51
51
"""
52
52
This is a dummy button, if pressed kicks user.
53
53
"""
54
54
await self .send_wrong_button_message_and_kick (interaction )
55
55
56
- @discord .ui .button (label = "Verify!" , row = 0 , style = discord .ButtonStyle .red )
56
+ @discord .ui .button (label = "Verify!" , row = 0 , custom_id = "Button_2" , style = discord .ButtonStyle .red )
57
57
async def verify_button_callback_red_2 (self , button : discord .ui .Button , interaction : discord .Interaction ):
58
58
"""
59
59
This is a dummy button, if pressed kicks user.
60
60
"""
61
61
await self .send_wrong_button_message_and_kick (interaction )
62
62
63
- @discord .ui .button (label = "Verify!" , row = 0 , style = discord .ButtonStyle .success )
63
+ @discord .ui .button (label = "Verify!" , row = 0 , custom_id = "Button_3" , style = discord .ButtonStyle .success )
64
64
async def verify_button_callback_green (self , button : discord .ui .Button , interaction : discord .Interaction ):
65
65
"""
66
66
This is the stuff that happens
@@ -75,7 +75,6 @@ async def verify_button_callback_green(self, button: discord.ui.Button, interact
75
75
76
76
embed = discord .Embed (title = "Welcome to Practical Python" , color = discord .Color .yellow ())
77
77
embed .set_thumbnail (url = "https://raw.githubusercontent.com/Xarlos89/PracticalPython/main/logo.png" )
78
-
79
78
if not verified :
80
79
guild = interaction .guild
81
80
roles = guild .roles
@@ -87,20 +86,21 @@ async def verify_button_callback_green(self, button: discord.ui.Button, interact
87
86
verified_role = discord .utils .get (roles , id = self .bot .server_settings .verified_role ['verified' ])
88
87
await user .add_roles (verified_role )
89
88
90
- log_channels_verification_log = await self .bot .fetch_channel (self .bot .server_settings .log_channel ["verification_log" ])
89
+ log_channels_verification_log = await self .bot .fetch_channel (
90
+ self .bot .server_settings .log_channel ["verification_log" ])
91
91
log_channels_join = await self .bot .fetch_channel (self .bot .server_settings .log_channel ["join_log" ])
92
92
93
93
await log_channels_verification_log .send (f"{ user .mention } has verified!" )
94
94
await log_channels_join .send (embed = embed_verified_success (user .mention , user .guild .member_count ))
95
95
96
- @discord .ui .button (label = "Verify!" , row = 0 , style = discord .ButtonStyle .red )
96
+ @discord .ui .button (label = "Verify!" , row = 0 , custom_id = "Button_4" , style = discord .ButtonStyle .red )
97
97
async def verify_button_callback_red_3 (self , button : discord .ui .Button , interaction : discord .Interaction ):
98
98
"""
99
99
This is a dummy button, if pressed kicks user.
100
100
"""
101
101
await self .send_wrong_button_message_and_kick (interaction )
102
102
103
- @discord .ui .button (label = "Verify!" , row = 0 , style = discord .ButtonStyle .red )
103
+ @discord .ui .button (label = "Verify!" , row = 0 , custom_id = "Button_5" , style = discord .ButtonStyle .red )
104
104
async def verify_button_callback_red_4 (self , button : discord .ui .Button , interaction : discord .Interaction ):
105
105
"""
106
106
This is a dummy button, if pressed kicks user.
@@ -127,7 +127,7 @@ async def add_verify_button(self, ctx):
127
127
"please click the **GREEN** 'Verify' button to confirm your identity and gain "
128
128
"access to the server. **If you click the RED button you will be kicked!** Feel free to introduce yourself and don't "
129
129
"hesitate to ask any questions. Happy coding!" )
130
-
130
+
131
131
await ctx .respond (button_message , view = AdminVerification (self .bot ))
132
132
133
133
async def cog_command_error (self , ctx : commands .Context , error : commands .CommandError ):
@@ -140,6 +140,21 @@ async def cog_command_error(self, ctx: commands.Context, error: commands.Command
140
140
raise error
141
141
142
142
143
+ class PersistentButton (commands .Cog ):
144
+ """
145
+ Listener for Adding the verification as a persistent listener
146
+ """
147
+
148
+ def __init__ (self , bot ):
149
+ self .bot = bot
150
+
151
+ # Registers a View for persistent listening
152
+ @commands .Cog .listener ()
153
+ async def on_ready (self ):
154
+ self .bot .add_view (AdminVerification (self .bot ))
155
+
156
+
143
157
def setup (bot ):
144
158
"""Required."""
145
159
bot .add_cog (VerifyHelper (bot ))
160
+ bot .add_cog (PersistentButton (bot ))
0 commit comments