Passed
Push — master ( eb55fd...7c4853 )
by Yohann
01:08
created

welcome_role.setup()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
from typing import Optional
2
3
from discord import TextChannel
4
from discord.ext import commands
5
6
from app.bot import Bot
7
8
CHANNEL_ID = 900370744263966821
9
ROLE_ID = 888527962935296091
10
11
12
class WorkerRole(commands.Cog):
13
    """A simple commands cog template."""
14
15
    def __init__(self, client: Bot):
16
        """Link to bot instance."""
17
        self.client: Bot = client
18
        self.channel: Optional[TextChannel] = None
19
20
    @commands.Cog.listener()
21
    async def on_ready(self):
22
        self.channel = self.client.guild.get_channel(CHANNEL_ID)
23
24
    @commands.Cog.listener()
25
    async def on_member_update(self, before, after):
26
        diff_roles = [
27
            role.id for role in after.roles if role not in before.roles
28
        ]
29
30
        if ROLE_ID in diff_roles:
31
            await self.channel.send(f"{after.mention}")
32
33
34
def setup(client: Bot):
35
    client.add_cog(WorkerRole(client))
36