Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. import random
  2. import discord
  3. import json
  4. import os
  5. import string
  6. import logging
  7. import asyncio
  8.  
  9. from discord.ext.commands import Bot
  10. from discord import Game
  11.  
  12. TOKEN = "NDY5ODg2NTMyNjk4NzY3MzYy.DjOVEw.hJkjXQActADukbaU65A_aZKDIxU"
  13. BOT_PREFIX = "!"
  14.  
  15. client = Bot(command_prefix=BOT_PREFIX)
  16. os.chdir(r'C:\Users\rob0058\PycharmProjects\cryptdm')
  17.  
  18.  
  19. @client.event
  20. async def on_member_join(member):
  21. with open('users.json', 'r') as f:
  22. users = json.load(f)
  23.  
  24. await update_data(users, member)
  25.  
  26. with open('users.json', 'w') as f:
  27. json.dump(users, f)
  28.  
  29.  
  30. @client.event
  31. async def on_message(message):
  32. with open('users.json', 'r') as f:
  33. users = json.load(f)
  34.  
  35. await client.process_commands(message)
  36. await update_data(users, message.author)
  37. await add_experience(users, message.author, 5)
  38. await level_up(users, message.author, message.channel)
  39.  
  40. with open('users.json', 'w') as f:
  41. json.dump(users, f)
  42. async def update_data(users, user):
  43. if not user.id in users:
  44. users[user.id] = {}
  45. users[user.id]['experience'] = 0
  46. users[user.id]['level'] = 1
  47. async def add_experience(users, user, exp):
  48. users[user.id]['experience'] += exp
  49. async def level_up(users, user, channel):
  50. experience = users[user.id]['experience']
  51. lvl_start = users[user.id]['level']
  52. lvl_end = int(experience ** (1 / 4))
  53.  
  54. if lvl_start < lvl_end:
  55. await client.send_message(channel, '{} has leveled up to level {}'.format(user.mention, lvl_end))
  56. users[user.id]['level'] = lvl_end
  57.  
  58.  
  59. @client.command(name='8ball',
  60. description="Answers a yes/no question.",
  61. brief="Answers a yes/no question.",
  62. aliases=['eight_ball', 'eightball', '8-ball'],
  63. pass_context=True)
  64. async def eight_ball(context):
  65. possible_responses = [
  66. 'This is a resounding no',
  67. 'It is not looking likely',
  68. 'Too hard to tell',
  69. 'It is quite possible',
  70. 'Definitely',
  71. ]
  72. await client.say(random.choice(possible_responses) + ", " + context.message.author.mention + ".")
  73. @client.command()
  74. async def square(number):
  75. squared_value = int(number) * int(number)
  76. await client.say(str(number) + " squard is " + str(squared_value))
  77. @client.command()
  78. async def add(a: int, b: int):
  79. await client.say(a + b)
  80. @client.command()
  81. async def cat():
  82. await client.say("https://media.giphy.com/media/JIX9t2j0ZTN9S/giphy.gif")
  83. @client.event
  84. async def on_ready():
  85. await client.change_presence(game=Game(name="with low level sorcerers."))
  86.  
  87.  
  88. client.run(TOKEN)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement