Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import discord
- import json
- import os
- import string
- import logging
- import asyncio
- from discord.ext.commands import Bot
- from discord import Game
- TOKEN = "NDY5ODg2NTMyNjk4NzY3MzYy.DjOVEw.hJkjXQActADukbaU65A_aZKDIxU"
- BOT_PREFIX = "!"
- client = Bot(command_prefix=BOT_PREFIX)
- os.chdir(r'C:\Users\rob0058\PycharmProjects\cryptdm')
- @client.event
- async def on_member_join(member):
- with open('users.json', 'r') as f:
- users = json.load(f)
- await update_data(users, member)
- with open('users.json', 'w') as f:
- json.dump(users, f)
- @client.event
- async def on_message(message):
- with open('users.json', 'r') as f:
- users = json.load(f)
- await client.process_commands(message)
- await update_data(users, message.author)
- await add_experience(users, message.author, 5)
- await level_up(users, message.author, message.channel)
- with open('users.json', 'w') as f:
- json.dump(users, f)
- async def update_data(users, user):
- if not user.id in users:
- users[user.id] = {}
- users[user.id]['experience'] = 0
- users[user.id]['level'] = 1
- async def add_experience(users, user, exp):
- users[user.id]['experience'] += exp
- async def level_up(users, user, channel):
- experience = users[user.id]['experience']
- lvl_start = users[user.id]['level']
- lvl_end = int(experience ** (1 / 4))
- if lvl_start < lvl_end:
- await client.send_message(channel, '{} has leveled up to level {}'.format(user.mention, lvl_end))
- users[user.id]['level'] = lvl_end
- @client.command(name='8ball',
- description="Answers a yes/no question.",
- brief="Answers a yes/no question.",
- aliases=['eight_ball', 'eightball', '8-ball'],
- pass_context=True)
- async def eight_ball(context):
- possible_responses = [
- 'This is a resounding no',
- 'It is not looking likely',
- 'Too hard to tell',
- 'It is quite possible',
- 'Definitely',
- ]
- await client.say(random.choice(possible_responses) + ", " + context.message.author.mention + ".")
- @client.command()
- async def square(number):
- squared_value = int(number) * int(number)
- await client.say(str(number) + " squard is " + str(squared_value))
- @client.command()
- async def add(a: int, b: int):
- await client.say(a + b)
- @client.command()
- async def cat():
- await client.say("https://media.giphy.com/media/JIX9t2j0ZTN9S/giphy.gif")
- @client.event
- async def on_ready():
- await client.change_presence(game=Game(name="with low level sorcerers."))
- client.run(TOKEN)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement