Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- from discord.ext.commands import Bot
- import asyncio
- import random
- import json
- import os
- bot = Bot(command_prefix='//')
- @bot.event
- async def on_ready():
- print('Logged in as')
- print(bot.user.name)
- print(bot.user.id)
- @bot.command()
- async def test():
- await bot.say("Successful")
- @bot.command()
- async def applications(user=None):
- userType = None
- try:
- user = int(user)
- userType = 'number'
- except:
- userType = 'name'
- if user != None:
- with open("apply_file.txt",'r') as apply_file:
- dict = json.load(apply_file)
- keyValues = dict.keys()
- dictValues = dict.values()
- if userType == 'name':
- application_list = list(dict.values())
- for x in application_list:
- xValue = x
- list2 = x.partition("': '")
- list2 = list(list2)
- list2.remove("': '")
- #for y, z in list2:
- y = list2[0]
- z = list2[1]
- a = (y[2:])
- a1 = (z[:-2])
- if a == user:
- break
- for x, y in zip(keyValues, dictValues):
- if y == xValue:
- keyValue = x
- e = discord.Embed(title="Application {0}".format(keyValue))
- e.add_field(name="User", value=a)
- e.add_field(name="Reason", value=a1)
- await bot.say(embed=e)
- elif userType == 'number':
- keyValue = user
- try:
- dictValue = dict[str(keyValue)]
- list2 = dictValue.partition("': '")
- list2 = list(list2)
- list2.remove("': '")
- #for y, z in list2:
- y = list2[0]
- z = list2[1]
- a = (y[2:])
- a1 = (z[:-2])
- e = discord.Embed(title="Application {0}".format(keyValue))
- e.add_field(name="User", value=a)
- e.add_field(name="Reason", value=a1)
- await bot.say(embed=e)
- except:
- await bot.say("{0} is not a valid ID".format(keyValue))
- else:
- await bot.say("You need to specify a user or id!")
- @bot.command(pass_context=True)
- async def apply(ctx, *reason):
- Reason = (' '.join(reason))
- if Reason == '':
- Reason = "No reason given"
- #"id":["user":"reason"]
- apply_list = {}
- if os.path.isfile("apply_file.txt"):
- with open("apply_file.txt",'r') as apply_file:
- apply_list = json.load(apply_file)
- ID = (len(apply_list) + 1)
- info = str({ctx.message.author.name : Reason})
- apply_list[ID] = info
- with open("apply_file.txt", 'w') as apply_file:
- json.dump(apply_list, apply_file)
- await bot.say('Thank you, {0}. Your application has been submitted and will be reviewed later.'.format(ctx.message.author.mention))
- bot.run('token')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement