Advertisement
Rastus22

Discord Bot 13/09

Sep 13th, 2017
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.59 KB | None | 0 0
  1. import discord
  2. from discord.ext import commands
  3. from datetime import *
  4. from dateutil.relativedelta import *
  5.  
  6. bot = commands.Bot(command_prefix='!')
  7. bot.remove_command("help")
  8.  
  9.  
  10. @bot.event
  11. async def on_ready():
  12.     print('Logged in as')
  13.     print(bot.user.name)
  14.     print(bot.user.id)
  15.     print('------')
  16.    
  17.  
  18. @bot.event
  19. async def on_message(message):
  20.     if message.content == 'There are **Unknown** remaining until the Cabal invasion and the destruction of The Tower. Eyes up, guardian.':
  21.         await bot.delete_message(message)
  22.     await bot.process_commands(message)
  23.    
  24.    
  25.    
  26. @bot.group(pass_context=True)
  27. async def countdown(ctx):
  28.     if ctx.invoked_subcommand is None:
  29.         await bot.say('!countdown <weekly/daily/xur>')    
  30.  
  31.        
  32. @countdown.command(name='weekly')
  33. async def weekly():
  34.     now = datetime.now()
  35.     today = date.today()
  36.     nextTue = today+relativedelta(weekday=TU(+2), hour = 19)
  37.     reset = nextTue - now
  38.     totalSeconds = reset.total_seconds()
  39.     timeTil = datetime(1,1,1) + timedelta(seconds = totalSeconds)
  40.    
  41.     days = timeTil.day-7
  42.     hours = timeTil.hour
  43.     minutes = timeTil.minute
  44.     seconds = timeTil.second
  45.  
  46.     await bot.say('The weekly reset is in ' + str(days) + ' days, ' + str(hours) + ' hours, ' + str(minutes) + ' minutes, and ' + str(seconds) + ' seconds.')
  47.    
  48. @countdown.command(name='xur')
  49. async def xur():
  50.     now = datetime.now()
  51.     today = date.today()
  52.     nextTue = today+relativedelta(weekday=FR(+2), hour = 19)
  53.     reset = nextTue - now
  54.     totalSeconds = reset.total_seconds()
  55.     timeTil = datetime(1,1,1) + timedelta(seconds = totalSeconds)
  56.    
  57.     days = timeTil.day-7
  58.     hours = timeTil.hour
  59.     minutes = timeTil.minute
  60.     seconds = timeTil.second
  61.  
  62.     await bot.say('Xur arrives in ' + str(days) + ' days, ' + str(hours) + ' hours, ' + str(minutes) + ' minutes, and ' + str(seconds) + ' seconds.')
  63.    
  64. @countdown.command(name='daily')
  65. async def daily():
  66.     now = datetime.now()
  67.     today = date.today()
  68.     if now.hour > 19:
  69.         nextTue = today+relativedelta(hour = 19)
  70.         nextTue += timedelta(days=1)
  71.     else:
  72.         nextTue = today+relativedelta(hour = 19)
  73.     reset = nextTue - now
  74.     totalSeconds = reset.total_seconds()
  75.     timeTil = datetime(1,1,1) + timedelta(seconds = totalSeconds)
  76.    
  77.  
  78.     hours = timeTil.hour
  79.     minutes = timeTil.minute
  80.     seconds = timeTil.second
  81.  
  82.     await bot.say('The daily reset is in ' + str(hours) + ' hours, ' + str(minutes) + ' minutes, and ' + str(seconds) + ' seconds.')
  83.  
  84.  
  85.    
  86.    
  87. @bot.group(pass_context=True)
  88. async def platform(ctx):
  89.     if ctx.invoked_subcommand is None:
  90.         await bot.say('!platform <join/leave> <xbox/playstation/pc>')      
  91.  
  92. @platform.command(pass_context=True, name ='join')
  93. async def join(ctx):
  94.     content = ctx.message.content.lower().split()
  95.     if len(content) >= 3:
  96.         if content[2] == 'pc':
  97.             await bot.say("Added to platform PC")
  98.             currentServer = ctx.message.server
  99.             pcRole = discord.utils.get(currentServer.roles, name="PC")
  100.             await bot.add_roles(ctx.message.author, pcRole)
  101.            
  102.         elif content[2] == 'xbox':
  103.             await bot.say("Added to platform Xbox")
  104.             currentServer = ctx.message.server
  105.             xboxRole = discord.utils.get(currentServer.roles, name="Xbox")
  106.             await bot.add_roles(ctx.message.author, xboxRole)
  107.         elif content[2] == 'playstation':
  108.        
  109.             await bot.say("Added to platform Playstation")
  110.             currentServer = ctx.message.server
  111.             playstationRole = discord.utils.get(currentServer.roles, name="Playstation")
  112.             await bot.add_roles(ctx.message.author, playstationRole)
  113.         else:
  114.             await bot.say('!platform <join/leave> <xbox/playstation/pc>')
  115.     else:
  116.         await bot.say('!platform <join/leave> <xbox/playstation/pc>')        
  117.        
  118. @platform.command(pass_context=True, name ='leave')
  119. async def leave(ctx):
  120.     content = ctx.message.content.lower().split()
  121.     if len(content) >= 3:
  122.         if content[2] == 'pc':
  123.             await bot.say("Removed from platform PC")
  124.             currentServer = ctx.message.server
  125.             pcRole = discord.utils.get(currentServer.roles, name="PC")
  126.             await bot.remove_roles(ctx.message.author, pcRole)
  127.            
  128.         elif content[2] == 'xbox':
  129.             await bot.say("Removed from platform Xbox")
  130.             currentServer = ctx.message.server
  131.             xboxRole = discord.utils.get(currentServer.roles, name="Xbox")
  132.             await bot.remove_roles(ctx.message.author, xboxRole)
  133.         elif content[2] == 'playstation':
  134.        
  135.             await bot.say("Removed from platform Playstation")
  136.             currentServer = ctx.message.server
  137.             playstationRole = discord.utils.get(currentServer.roles, name="Playstation")
  138.             await bot.remove_roles(ctx.message.author, playstationRole)
  139.         else:
  140.             await bot.say('!platform <join/leave> <xbox/playstation/pc>')
  141.     else:
  142.         await bot.say('!platform <join/leave> <xbox/playstation/pc>')      
  143.        
  144. #Test bot id
  145. #bot.run("MzU1OTYwMDgxODUxODc1MzMw.DJUZLQ.c8s7v0OxhKlHcOMW4Cy3P-c9Bbk")
  146.  
  147. #Ember bot id
  148. bot.run("MzM4MTYxMzgyMTY1OTcwOTQ0.DJUhGA.FGsVKs7uqsv1TdJIybe1CJHDdoY")
  149.  
  150. import discord
  151. from discord.ext import commands
  152. from datetime import *
  153. from dateutil.relativedelta import *
  154.  
  155. bot = commands.Bot(command_prefix='!')
  156. bot.remove_command("help")
  157.  
  158.  
  159. @bot.event
  160. async def on_ready():
  161.     print('Logged in as')
  162.     print(bot.user.name)
  163.     print(bot.user.id)
  164.     print('------')
  165.    
  166.  
  167. @bot.event
  168. async def on_message(message):
  169.     if message.content == 'There are **Unknown** remaining until the Cabal invasion and the destruction of The Tower. Eyes up, guardian.':
  170.         await bot.delete_message(message)
  171.     await bot.process_commands(message)
  172.    
  173.    
  174.    
  175. @bot.group(pass_context=True)
  176. async def countdown(ctx):
  177.     if ctx.invoked_subcommand is None:
  178.         await bot.say('!countdown <weekly/daily/xur>')    
  179.  
  180.        
  181. @countdown.command(name='weekly')
  182. async def weekly():
  183.     now = datetime.now()
  184.     today = date.today()
  185.     nextTue = today+relativedelta(weekday=TU(+2), hour = 19)
  186.     reset = nextTue - now
  187.     totalSeconds = reset.total_seconds()
  188.     timeTil = datetime(1,1,1) + timedelta(seconds = totalSeconds)
  189.    
  190.     days = timeTil.day-7
  191.     hours = timeTil.hour
  192.     minutes = timeTil.minute
  193.     seconds = timeTil.second
  194.  
  195.     await bot.say('The weekly reset is in ' + str(days) + ' days, ' + str(hours) + ' hours, ' + str(minutes) + ' minutes, and ' + str(seconds) + ' seconds.')
  196.    
  197. @countdown.command(name='xur')
  198. async def xur():
  199.     now = datetime.now()
  200.     today = date.today()
  201.     nextTue = today+relativedelta(weekday=FR(+2), hour = 19)
  202.     reset = nextTue - now
  203.     totalSeconds = reset.total_seconds()
  204.     timeTil = datetime(1,1,1) + timedelta(seconds = totalSeconds)
  205.    
  206.     days = timeTil.day-7
  207.     hours = timeTil.hour
  208.     minutes = timeTil.minute
  209.     seconds = timeTil.second
  210.  
  211.     await bot.say('Xur arrives in ' + str(days) + ' days, ' + str(hours) + ' hours, ' + str(minutes) + ' minutes, and ' + str(seconds) + ' seconds.')
  212.    
  213. @countdown.command(name='daily')
  214. async def daily():
  215.     now = datetime.now()
  216.     today = date.today()
  217.     if now.hour > 19:
  218.         nextTue = today+relativedelta(hour = 19)
  219.         nextTue += timedelta(days=1)
  220.     else:
  221.         nextTue = today+relativedelta(hour = 19)
  222.     reset = nextTue - now
  223.     totalSeconds = reset.total_seconds()
  224.     timeTil = datetime(1,1,1) + timedelta(seconds = totalSeconds)
  225.    
  226.  
  227.     hours = timeTil.hour
  228.     minutes = timeTil.minute
  229.     seconds = timeTil.second
  230.  
  231.     await bot.say('The daily reset is in ' + str(hours) + ' hours, ' + str(minutes) + ' minutes, and ' + str(seconds) + ' seconds.')
  232.  
  233.  
  234.    
  235.    
  236. @bot.group(pass_context=True)
  237. async def platform(ctx):
  238.     if ctx.invoked_subcommand is None:
  239.         await bot.say('!platform <join/leave> <xbox/playstation/pc>')      
  240.  
  241. @platform.command(pass_context=True, name ='join')
  242. async def join(ctx):
  243.     content = ctx.message.content.lower().split()
  244.     if len(content) >= 3:
  245.         if content[2] == 'pc':
  246.             await bot.say("Added to platform PC")
  247.             currentServer = ctx.message.server
  248.             pcRole = discord.utils.get(currentServer.roles, name="PC")
  249.             await bot.add_roles(ctx.message.author, pcRole)
  250.            
  251.         elif content[2] == 'xbox':
  252.             await bot.say("Added to platform Xbox")
  253.             currentServer = ctx.message.server
  254.             xboxRole = discord.utils.get(currentServer.roles, name="Xbox")
  255.             await bot.add_roles(ctx.message.author, xboxRole)
  256.         elif content[2] == 'playstation':
  257.        
  258.             await bot.say("Added to platform Playstation")
  259.             currentServer = ctx.message.server
  260.             playstationRole = discord.utils.get(currentServer.roles, name="Playstation")
  261.             await bot.add_roles(ctx.message.author, playstationRole)
  262.         else:
  263.             await bot.say('!platform <join/leave> <xbox/playstation/pc>')
  264.     else:
  265.         await bot.say('!platform <join/leave> <xbox/playstation/pc>')        
  266.        
  267. @platform.command(pass_context=True, name ='leave')
  268. async def leave(ctx):
  269.     content = ctx.message.content.lower().split()
  270.     if len(content) >= 3:
  271.         if content[2] == 'pc':
  272.             await bot.say("Removed from platform PC")
  273.             currentServer = ctx.message.server
  274.             pcRole = discord.utils.get(currentServer.roles, name="PC")
  275.             await bot.remove_roles(ctx.message.author, pcRole)
  276.            
  277.         elif content[2] == 'xbox':
  278.             await bot.say("Removed from platform Xbox")
  279.             currentServer = ctx.message.server
  280.             xboxRole = discord.utils.get(currentServer.roles, name="Xbox")
  281.             await bot.remove_roles(ctx.message.author, xboxRole)
  282.         elif content[2] == 'playstation':
  283.        
  284.             await bot.say("Removed from platform Playstation")
  285.             currentServer = ctx.message.server
  286.             playstationRole = discord.utils.get(currentServer.roles, name="Playstation")
  287.             await bot.remove_roles(ctx.message.author, playstationRole)
  288.         else:
  289.             await bot.say('!platform <join/leave> <xbox/playstation/pc>')
  290.     else:
  291.         await bot.say('!platform <join/leave> <xbox/playstation/pc>')      
  292.        
  293. #Test bot id
  294. #bot.run("MzU1OTYwMDgxODUxODc1MzMw.DJUZLQ.c8s7v0OxhKlHcOMW4Cy3P-c9Bbk")
  295.  
  296. #Ember bot id
  297. bot.run("MzM4MTYxMzgyMTY1OTcwOTQ0.DJUhGA.FGsVKs7uqsv1TdJIybe1CJHDdoY")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement