10
10
import os #
11
11
import discord #
12
12
from dotenv import load_dotenv #
13
+ import random #
13
14
#
14
15
#################################
15
16
16
17
17
- load_dotenv ()
18
- token = os .getenv ('DISCORD_TOKEN' )
18
+ load_dotenv () # Loads .env file
19
+ TOKEN = os .getenv ('DISCORD_TOKEN' ) # Tells the program to use the token provided in .env
20
+ client = discord .Client () # Tells the program to use the default Client class
19
21
20
- client = discord .Client ()
21
22
22
- @client .event
23
+ @client .event # Logs a sucessful connection to the Discord server
23
24
async def on_ready ():
24
- print (f'{ client .user } has connected to Discord !' )
25
+ print (f'{ client .user . name } has sucessfully connected to the server !' )
25
26
26
- client .run (token )
27
+
28
+ @client .event # Responds to a new member joining the server
29
+ async def on_member_join (member ):
30
+ await member .create_dm () # Creates a DM with the user and sends a message
31
+ await member .dm_channel .send (
32
+ f"Hi { member .name } , welcome to Konnor's Discord server. Please set your "
33
+ "nickname to match the naming scheme used on the server. For example, if "
34
+ "my name was John, my nickname would be \" Protobot | John\" . Please also "
35
+ "make sure to read any messages pinned in the #important channel."
36
+ )
37
+
38
+
39
+ @client .event # Responds to a user sending a message in the server
40
+ async def on_message (message ):
41
+ if message .author == client .user :
42
+ return # Ensures ProtoBot will not respond to its own messages
43
+
44
+ b99_quotes = [
45
+ "I'm the human form of the 💯 emoji." ,
46
+ "Bingpot!" ,
47
+ "Nine-nine!" ,
48
+ (
49
+ "Cool. Cool cool cool cool cool cool cool, "
50
+ "no doubt no doubt no doubt no doubt."
51
+ ),
52
+ "With all due respect, I am gonna completely ignore everything you just said." ,
53
+ (
54
+ "The English language can not fully capture the depth and complexity of my "
55
+ "thoughts, so I’m incorporating emojis into my speech to better express myself. 😉."
56
+ ),
57
+ "I’d like your $8-est bottle of wine, please." ,
58
+ "But if you’re here, who’s guarding Hades?"
59
+ ]
60
+
61
+ ways_to_say_i_am = ["im" , "i'm" , "i am" ]
62
+
63
+ if message .content == '99!' :
64
+ response = random .choice (b99_quotes )
65
+ await message .channel .send (response ) # Sends a Brooklyn 99 quote whenever a user says '99!'
66
+
67
+ elif 'i\' m ' or 'im ' or 'i am ' in message .content .lower ():
68
+ user_message = message .content .split ()
69
+ for i in range (len (user_message )):
70
+ if len (user_message ) - i < 2 :
71
+ break
72
+
73
+ elif user_message [i ].lower () in ways_to_say_i_am :
74
+ await message .channel .send ("Hi " + " " .join (user_message [i + 1 :]) + "! I'm dad!" )
75
+ break
76
+
77
+ elif len (user_message ) - i < 3 :
78
+ break
79
+
80
+ elif user_message [i ].lower () + " " + user_message [i + 1 ].lower () in ways_to_say_i_am :
81
+ await message .channel .send ("Hi " + " " .join (user_message [i + 2 :]) + "! I'm dad!" )
82
+ break
83
+
84
+
85
+
86
+ client .run (TOKEN )
0 commit comments