Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- import random
- import requests
- import io
- import json
- import os.path
- import os
- import sys
- import time
- from datetime import tzinfo, datetime, timedelta
- from pprint import pprint
- from discord.ext import commands
- from discord.ext.commands import bot
- bot = commands.Bot(command_prefix=("k","K"))
- bot.remove_command('help')
- @bot.event
- async def on_ready():
- print ("I am running on " + bot.user.name)
- print ("With the ID: " + bot.user.id)
- @bot.event
- async def on_message(message):
- if message.author == bot.user:
- return
- if message.author.bot:
- return
- await bot.process_commands(message)
- @bot.command(pass_context=True)
- async def test(ctx):
- embed = discord.Embed(title="Testing", colour=discord.Colour(0xf3c04f))
- embed.set_footer(text="Custom Reaction")
- msg = await bot.send_message(ctx.message.channel, embed=embed)
- emoji1 = discord.utils.get(bot.get_all_emojis(), name='number1')
- emoji2 = discord.utils.get(bot.get_all_emojis(), name='number2')
- if get_espace1(ctx.message.author.id) <= 0:
- await bot.add_reaction(msg, emoji1)
- if get_espace2(ctx.message.author.id) <= 0:
- await bot.add_reaction(msg, emoji2)
- emojis = [emoji1, emoji2]
- while emojis:
- res = await bot.wait_for_reaction(emoji=emojis, message=msg, user=ctx.message.author)
- if res:
- reaction, ctx.message.author = res
- emojis = [e for e in emojis if e != reaction]
- if str(reaction.emoji) == "<:number1:530776225552007168>":
- await bot.send_message(ctx.message.channel, "add 1")
- user_add_espace1(ctx.message.author.id, 1)
- await bot.edit_message(msg, embed = embed)
- if str(reaction.emoji) == "<:number1:530776225535361044>":
- await bot.send_message(ctx.message.channel, "add 2")
- user_add_espace2(ctx.message.author.id, 1)
- await bot.edit_message(msg, embed = embed)
- def user_add_space(user_id: int, xp: int):
- if os.path.isfile("bot/space.json"):
- try:
- with open('bot/space.json', 'r') as fp:
- users = json.load(fp)
- users[user_id]['space'] += xp
- with open('bot/space.json', 'w') as fp:
- json.dump(users, fp, sort_keys=True, indent=4)
- except KeyError:
- with open('bot/space.json', 'r') as fp:
- users = json.load(fp)
- users[user_id] = {}
- users[user_id]['space'] = xp
- with open('bot/space.json', 'w') as fp:
- json.dump(users, fp, sort_keys=True, indent=4)
- else:
- users = {user_id: {}}
- users[user_id]['space'] = xp
- with open('bot/space.json', 'w') as fp:
- json.dump(users, fp, sort_keys=True, indent=4)
- def get_space(user_id: int):
- if os.path.isfile('bot/space.json'):
- try:
- with open('bot/space.json', 'r') as fp:
- users = json.load(fp)
- return users[user_id]['space']
- except KeyError:
- return 0
- bot.run("TOKEN")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement