-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamerTagBot.py
More file actions
50 lines (42 loc) · 1.71 KB
/
StreamerTagBot.py
File metadata and controls
50 lines (42 loc) · 1.71 KB
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 asyncio
import config
client = discord.Client()
@client.event
async def on_ready():
print("Streamer Tag Bot Online!")
print("Scanning for users that are streaming.\n\n")
def titleEnabled(members):
if config.enableTitle is True:
return config.title in str(members.activities)
else:
return True
def gameEnabled(members):
game = "name=\'" + config.gameName + "\'"
if config.enableGame is True:
return game in str(members.activities)
else:
return True
async def twitchCheck():
await client.wait_until_ready()
guild = client.get_guild(config.guildID)
role = discord.utils.get(guild.roles, id=config.roleID)
while not client.is_closed():
try:
guildMembers = guild.members
for members in guildMembers:
isStreaming = "Streaming" in str(members.activities)
hasRole = role in members.roles
isBot = members.bot is True
if ((titleEnabled(members) and gameEnabled(members)) and isStreaming) and not hasRole and not isBot:
print("Added role to " + str(members.name))
await members.add_roles(role)
if ((not titleEnabled(members) or not gameEnabled(members)) or not isStreaming) and hasRole and not isBot:
print("Removed role from " + str(members.name))
await members.remove_roles(role)
await asyncio.sleep(config.updateDelay)
except Exception as e:
print(e)
await asyncio.sleep(1)
client.loop.create_task(twitchCheck())
client.run(config.botToken)