Advertisement
az4521

Discord Christmas Bot

Dec 8th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. import discord
  2. from time import sleep
  3. client = discord.Client()
  4. def ret_key(x): return x.name.lower()
  5. @client.event
  6. async def on_ready():
  7.     print('Logged in as')
  8.     print(client.user.name)
  9.     print(client.user.id)
  10.     print('------')
  11.  
  12.     #things you can change here
  13.     colour_change_delay = 1
  14.     userlist_update_delay = 5
  15.     role_0_name = "christmas-0"
  16.     role_1_name = "christmas-1"
  17.     bot_key = ""
  18.  
  19.     #no touch below here
  20.     state =0
  21.     timer =0
  22.     users =[]
  23.     server=[x for x in client.servers][0]
  24.     role=[0,0]
  25.     role[0]=discord.utils.find(lambda m: m.name.lower()==role_0_name.lower(),server.roles)
  26.     role[1]=discord.utils.find(lambda m: m.name.lower()==role_1_name.lower(),server.roles)
  27.     while 1:
  28.         try:
  29.             sleep(colour_change_delay)
  30.             users=sorted([x for x in server.members if (role[0] in x.roles) and str(x.status).lower()!="offline"],key=ret_key)
  31.             if not timer:
  32.                 for i in range(len(users)):
  33.                     if i%2:
  34.                         if role[1] not in users[i].roles:
  35.                             await client.add_roles(users[i], role[1])
  36.                     else:
  37.                         if role[1] in users[i].roles:
  38.                             await client.remove_roles(users[i], role[1])
  39.             state=(state+1)%2
  40.             clr = discord.Colour(((255<<16)+(0<<8)+0))
  41.             await client.edit_role(server, role[state], colour=clr)
  42.             clr = discord.Colour(((0<<16)+(255<<8)+0))
  43.             await client.edit_role(server, role[(state+1)%2], colour=clr)
  44.             timer=(timer+1)%userlist_update_delay
  45.         except Exception as e: print(e);break
  46. client.run(bot_key)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement