Skip to content

Commit

Permalink
Adding roles
Browse files Browse the repository at this point in the history
NA RAZIE TYLKO NA TESTOWYM SERWERZE - zrobione dodawanie roli, do zrobienia usuwanie roli
  • Loading branch information
nikisaku committed Mar 14, 2021
1 parent bb04319 commit 30f2bd4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
*.*~
node_modules
venv/
41 changes: 41 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
VERIFICATION_MESSAGE_ID = 820693368182013952
VERIFICATION_ROLE_ID = 820690464100581377

client = discord.Client()

Expand All @@ -30,6 +32,7 @@
channel_ids = []
trivia_channel_ids = []
events_channel_ids = []
roles_channel_ids = []


@aiocron.crontab('15 5 * * *')
Expand Down Expand Up @@ -60,6 +63,34 @@ async def cronjob4():
await client.get_channel(channel_id).send("Zapraszamy na kanał głosowy Relaks na wspólną kawę! ☕")



def compare_emojis(reaction_emoji):
return reaction_emoji.name == "🔑"

@client.event
async def on_raw_reaction_add(reaction):
print("tutaj")
print(reaction.emoji.name)
if reaction.message_id != 820693368182013952:
return
if compare_emojis(reaction.emoji):
verification_role = discord.utils.get(reaction.member.guild.roles, id=VERIFICATION_ROLE_ID)
await reaction.member.add_roles(verification_role)
print("role added")

@client.event
async def on_raw_reaction_remove(reaction):
if reaction.message_id != 820693368182013952:
return
if compare_emojis(reaction.emoji):
# guild_id + user_id -> member.id / member object
guild = client.get_guild(reaction.guild_id)
member = discord.utils.get(guild.members, id=reaction.user_id)
# member = client.get_member(reaction.user_id)
verification_role = discord.utils.get(guild.roles, id=VERIFICATION_ROLE_ID)
await member.remove_roles(verification_role)
print("role removed")

@client.event
async def on_ready():
global channel_ids
Expand All @@ -73,6 +104,16 @@ async def on_ready():
trivia_channel_ids.append(channel.id)
if 'wydarzenia' in channel.name:
events_channel_ids.append(channel.id)
if 'role' in channel.name:
roles_channel_ids.append(channel.id)
try:
msg = await channel.fetch_message(VERIFICATION_MESSAGE_ID)
print(msg.content)
except discord.NotFound:
# TODO zmień na coś lepszego
print("Wiadomość weryfikacyjna o tym ID nie istnieje")
# await client.get_channel(channel.id).send("bot is online")



client.run(TOKEN)

0 comments on commit 30f2bd4

Please sign in to comment.