-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.py
123 lines (100 loc) · 3.4 KB
/
bot.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import os
from dotenv import load_dotenv
import discord
from discord import app_commands
# Get variables from .env file
load_dotenv()
token = os.environ['TOKEN']
logo_url = os.environ['LOGO_URL']
logo_square_url = os.environ['LOGO_SQUARE_URL']
# Set guild ID
GUILD_ID = 1016499658471780392
# Set up logging
discord.utils.setup_logging()
# Set intents
intents = discord.Intents.default()
intents.members = True
# Create client with intents and set up slash commands
client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)
commands_synced = False
@client.event
async def on_ready():
print(f"We have logged in as {client.user}")
global commands_synced
if not commands_synced:
await tree.sync(guild=discord.Object(id=GUILD_ID))
commands_synced = True
@client.event
async def on_member_join(member):
guild = client.get_guild(GUILD_ID)
general_channel = guild.get_channel(1016499658962501674)
# Create welcome embed
embed = discord.Embed(
color=discord.Color.blue(),
title=f"Welcome to OA Code, {member.display_name}!",
description="Be sure to read <#1016514622943146054>, " +
"and enjoy your stay! " +
"Let's make some awesome stuff this year! :D",
timestamp=member.joined_at
)
embed.set_image(url=logo_url)
embed.set_footer(text=member, icon_url=member.display_avatar)
await general_channel.send(member.mention, embed=embed)
# Slash commands
@tree.command(description="Sends contact information for OA Code.",
guild=discord.Object(id=GUILD_ID))
async def contact(interaction: discord.Interaction):
embed = discord.Embed(
color=discord.Color.blue(),
title="Contact OA Code",
description="Here is our contact information!",
)
embed.set_thumbnail(url=logo_square_url)
embed.add_field(
name="Instagram",
value=("<:instagram:1019078879396249620> " +
"[@oa.code](https://www.instagram.com/oa.code/)"),
inline=False
)
embed.add_field(
name="Discord",
value=("<:discord:1019079092995362867> " +
"[is.gd/oacodediscord](https://is.gd/oacodediscord)"),
inline=False
)
embed.add_field(
name="Anna Lee (President)",
value=("📧 [email protected]"),
inline=False
)
embed.add_field(
name="Angelina Zhang (President)",
value=("📧 [email protected]"),
inline=False
)
embed.add_field(
name="Mr. Wai (Advisor)",
value=("📧 [email protected]"),
inline=False
)
await interaction.response.send_message(embed=embed)
@tree.command(description="Displays the next meeting date for OA Code.",
guild=discord.Object(id=GUILD_ID))
async def nextmeeting(interaction: discord.Interaction):
embed = discord.Embed(
color=discord.Color.blue(),
title="Next Meeting",
description="Our next meeting is on "+
"**September 14th, 2022** **during lunch**.",
)
embed.set_thumbnail(url=logo_square_url)
embed.add_field(
name="Meeting",
value=("We will be meeting on " +
"**September 14th, 2022** **during lunch**. " +
"We will be going over the basics of Python."),
inline=False
)
await interaction.response.send_message(embed=embed)
client.run(token)