-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
50 lines (36 loc) · 1.46 KB
/
app.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
import discord
import logging
from os import getenv
logging.basicConfig(level=logging.INFO)
client = discord.Client()
FLAG = getenv("FLAG")
TOKEN = getenv("TOKEN")
GUILD_ID = 746067092695941201
ROLE_ID = 973663565439467541
ADMIN_ID = 137662189891878913
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
print(client.guilds)
@client.event
async def on_message(message):
if message.author == client.user:
return
if not isinstance(message.channel, discord.DMChannel):
return
if FLAG not in message.content:
logging.info("%s invalid flag (%s)", message.author.id, message.content)
return await message.channel.send(f"It appears that the flag is not correct, try again?")
guild = client.get_guild(GUILD_ID)
role = guild.get_role(ROLE_ID)
if not guild or not role:
logging.warning("guild: %s, role: %s", guild, role)
return await message.channel.send(f"Something horrible has happened. Please contact <@{ADMIN_ID}>")
member = await guild.fetch_member(message.author.id)
if not member:
logging.info("%s sent flag, but is not in the guild", message.author.id)
return await message.channel.send(f"It appears that you're not a member of KNCyber server.")
logging.info("adding role to '%s'", message.author.id)
await member.add_roles(role)
await message.channel.send("Your flag seems to be correct! Welcome to KNCyber :)")
client.run(TOKEN)