Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. import discord
  2. import random
  3. import requests
  4. import io
  5. import json
  6. import os.path
  7. import os
  8. import sys
  9. import time
  10. from datetime import tzinfo, datetime, timedelta
  11. from pprint import pprint
  12. from discord.ext import commands
  13. from discord.ext.commands import bot
  14.  
  15. bot = commands.Bot(command_prefix=("k","K"))
  16.  
  17.  
  18. bot.remove_command('help')
  19. @bot.event
  20. async def on_ready():
  21. print ("I am running on " + bot.user.name)
  22. print ("With the ID: " + bot.user.id)
  23.  
  24. @bot.event
  25. async def on_message(message):
  26.  
  27. if message.author == bot.user:
  28. return
  29. if message.author.bot:
  30. return
  31. await bot.process_commands(message)
  32.  
  33.  
  34.  
  35. @bot.command(pass_context=True)
  36. async def test(ctx):
  37.  
  38. embed = discord.Embed(title="Testing", colour=discord.Colour(0xf3c04f))
  39. embed.set_footer(text="Custom Reaction")
  40. msg = await bot.send_message(ctx.message.channel, embed=embed)
  41. emoji1 = discord.utils.get(bot.get_all_emojis(), name='number1')
  42. emoji2 = discord.utils.get(bot.get_all_emojis(), name='number2')
  43.  
  44. if get_espace1(ctx.message.author.id) <= 0:
  45. await bot.add_reaction(msg, emoji1)
  46. if get_espace2(ctx.message.author.id) <= 0:
  47. await bot.add_reaction(msg, emoji2)
  48.  
  49. emojis = [emoji1, emoji2]
  50. while emojis:
  51. res = await bot.wait_for_reaction(emoji=emojis, message=msg, user=ctx.message.author)
  52. if res:
  53. reaction, ctx.message.author = res
  54. emojis = [e for e in emojis if e != reaction]
  55.  
  56. if str(reaction.emoji) == "<:number1:530776225552007168>":
  57.  
  58. await bot.send_message(ctx.message.channel, "add 1")
  59. user_add_espace1(ctx.message.author.id, 1)
  60. await bot.edit_message(msg, embed = embed)
  61.  
  62.  
  63. if str(reaction.emoji) == "<:number1:530776225535361044>":
  64.  
  65. await bot.send_message(ctx.message.channel, "add 2")
  66. user_add_espace2(ctx.message.author.id, 1)
  67. await bot.edit_message(msg, embed = embed)
  68.  
  69.  
  70.  
  71.  
  72.  
  73. def user_add_space(user_id: int, xp: int):
  74. if os.path.isfile("bot/space.json"):
  75. try:
  76. with open('bot/space.json', 'r') as fp:
  77. users = json.load(fp)
  78. users[user_id]['space'] += xp
  79. with open('bot/space.json', 'w') as fp:
  80. json.dump(users, fp, sort_keys=True, indent=4)
  81. except KeyError:
  82. with open('bot/space.json', 'r') as fp:
  83. users = json.load(fp)
  84. users[user_id] = {}
  85. users[user_id]['space'] = xp
  86. with open('bot/space.json', 'w') as fp:
  87. json.dump(users, fp, sort_keys=True, indent=4)
  88. else:
  89. users = {user_id: {}}
  90. users[user_id]['space'] = xp
  91. with open('bot/space.json', 'w') as fp:
  92. json.dump(users, fp, sort_keys=True, indent=4)
  93.  
  94.  
  95.  
  96. def get_space(user_id: int):
  97. if os.path.isfile('bot/space.json'):
  98. try:
  99. with open('bot/space.json', 'r') as fp:
  100. users = json.load(fp)
  101. return users[user_id]['space']
  102. except KeyError:
  103. return 0
  104.  
  105.  
  106. bot.run("TOKEN")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement