""" Copyright (C) 2021 Lexzach This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . """ import sys import time import asyncio import discord from discord.ext import commands import os.path import random from random import randint import re from items import itemList, unusualList import numpy import sqlite3 from datetime import datetime client = commands.Bot(command_prefix='tf.') conn = sqlite3.connect("itemServ.db") itemSrv = conn.cursor() client.remove_command('help') # itemSrv.execute("CREATE TABLE users(user_id integer PRIMARY KEY, items list, crates_unboxed integer)") # conn.commit() items = itemList @client.event async def on_ready(): print("Bot has successfully connected.") print("") print("Bot made by:") print(" _ _ ") print("| | _____ __ _____ _ __| |_ ") print("| |__/ -_) \ /|_ / _` / _| ' \ ") print("|____\___/_\_\/__\__,_\__|_||_|") print("Ver 1.3") await client.change_presence(status=discord.Status.online, activity=discord.Game("tf.help")) def unboxCalc(): final = "" itemUnboxed = items[randint(0,int(len(items))-1)] quality = "" unusual = False if randint(0,100) > 98: quality = "Elite Grade " elif randint(0, 100) <= 8: quality = "Commando Grade " elif randint(0,100) <= 16: quality = "Mercenary Grade " if randint(1,100) == 100: effect = unusualList[randint(0,int(len(unusualList))-1)] quality = "Unusual "+quality unusual = True if randint(0,10) == 10: quality = "Strange "+quality if randint(0,10000) == 10000: quality = "Community " if quality == "": final = itemUnboxed else: if unusual == False: final = quality + itemUnboxed else: final = quality + itemUnboxed + " (★ Unusual Effect: "+effect+")" print("Generated new item: "+final) return final @client.command() async def help(ctx): print("Command: help") embedHelp = discord.Embed(title = "", color = discord.Colour.green()) embedHelp.add_field(name = 'TF2 Virtual Trading', value = "Bot Prefix: tf.\n\n Commands:\n tf.help - Show this menu\n tf.unbox - Unbox a new item\n tf.inventory (@user) - View your inventory or someone elses\n tf.trade (@user) - Trade with someone\n tf.collectors - Combine 10 copies of an item into one collectors copy") embedHelp.set_footer(text="Direct any bugs to Lexzach#3215") await ctx.send(embed=embedHelp) @client.command() @commands.cooldown(1, 1800, commands.BucketType.user) async def unbox(ctx): bonus = False bonusItem = "" await ctx.message.delete(delay=60) print("\nUser ID #"+str(ctx.author.id)+" started an unbox") new = False itemSrv.execute("SELECT count(name) FROM sqlite_master WHERE type='table' AND name='"+str(ctx.author.id)+"'") conn.commit() if int(itemSrv.fetchone()[0]) == 0: itemSrv.execute("create table if not exists '"+str(ctx.author.id)+"'(items list)") now = datetime.now() now = now.strftime('%d/%m/%Y %H:%M:%S') new = True itemSrv.execute("INSERT INTO '"+str(ctx.author.id)+"'(items) VALUES('[Untradable] Tester Badge ( "+now+" )')") conn.commit() embedUnbox = discord.Embed(title = "", color = discord.Colour.green()) embedUnbox.add_field(name = '**Unboxing your loot.\n5**', value = "<@" + str(ctx.author.id)+">") embedUnbox4 = discord.Embed(title = "", color = discord.Colour.green()) embedUnbox4.add_field(name = '**Unboxing your loot..\n4**', value = "<@" + str(ctx.author.id)+">") embedUnbox3 = discord.Embed(title = "", color = discord.Colour.green()) embedUnbox3.add_field(name = '**Unboxing your loot...\n3**', value = "<@" + str(ctx.author.id)+">") embedUnbox2 = discord.Embed(title = "", color = discord.Colour.green()) embedUnbox2.add_field(name = '**Unboxing your loot.\n2**', value = "<@" + str(ctx.author.id)+">") embedUnbox1 = discord.Embed(title = "", color = discord.Colour.green()) embedUnbox1.add_field(name = '**Unboxing your loot..\n1**', value = "<@" + str(ctx.author.id)+">") item = unboxCalc() if random.randint(1,5) == 5: bonus = True bonusItem = "Mann Co. Supply Crate Key" print("Generated new item: "+bonusItem) if "Unusual" in item: #----------------------------------------------------------------------------Add effects embedFound = discord.Embed(title = "", color = 0x8650AC) elif "Elite Grade" in item: embedFound = discord.Embed(title = "", color = 0xEB4B4B) elif "Commando Grade" in item: embedFound = discord.Embed(title = "", color = 0x8847FF) elif "Commando Grade" in item: embedFound = discord.Embed(title = "", color = 0x4B69FF) elif "Strange" in item: embedFound = discord.Embed(title = "", color = 0xCF6A32) elif "Community" in item: embedFound = discord.Embed(title = "", color = 0x70B04A) elif "Mercenary Grade" in item: embedFound = discord.Embed(title = "", color = 0x4B69FF) else: embedFound = discord.Embed(title = "", color = 0xFFD700) if new == True: embedFound.add_field(name = '**You unboxed:\n||'+item + "||\n||First unbox: [Untradable] Tester Badge ( "+now+" )"+'||**', value = "<@" + str(ctx.author.id)+">") else: if bonus == False: embedFound.add_field(name = '**You unboxed:\n||'+item+'||**', value = "<@" + str(ctx.author.id)+">") else: embedFound.add_field(name = '**You unboxed:\n||'+item+"||\n||"+bonusItem+'||**', value = "<@" + str(ctx.author.id)+">") item = item.replace("'", "") item = item.replace('"', "") itemSrv.execute("INSERT INTO '"+str(ctx.author.id)+"'(items) VALUES('"+item+"')") if bonus == True: itemSrv.execute("INSERT INTO '"+str(ctx.author.id)+"'(items) VALUES('"+bonusItem+"')") conn.commit() msg = await ctx.send(embed=embedUnbox) await asyncio.sleep(1) await msg.edit(embed=embedUnbox4) await asyncio.sleep(1) await msg.edit(embed=embedUnbox3) await asyncio.sleep(1) await msg.edit(embed=embedUnbox2) await asyncio.sleep(1) await msg.edit(embed=embedUnbox1) await asyncio.sleep(1) await msg.edit(embed=embedFound) @unbox.error async def unbox_error(ctx, error): await ctx.message.delete(delay=10) embedTooLong = discord.Embed(title = "", color = discord.Colour.red()) embedTooLong.add_field(name = "**You must wait "+str(round(error.retry_after/60)) +" minutes before your next unbox**".format(error.retry_after), value = "<@" + str(ctx.author.id)+">") await ctx.send(embed=embedTooLong, delete_after=10) @client.command() async def inventory(ctx, *args): await ctx.message.delete(delay=60) someoneElse = False error = False if str(args) == "()": inventory = discord.Embed(title = "", color = discord.Colour.blue()) itemSrv.execute("SELECT count(name) FROM sqlite_master WHERE type='table' AND name='"+str(ctx.author.id)+"'") if int(itemSrv.fetchone()[0]) != 0: itemSrv.execute("SELECT * FROM '"+ str(ctx.author.id)+"'") print("\nUser ID #"+str(ctx.author.id)+" requested to see their inventory") else: print("\nUser ID #"+str(ctx.author.id)+" requested to see their inventory, but they don't have any items") error = True userNotFound = discord.Embed(title = "", color = discord.Colour.red()) userNotFound.add_field(name = "**You don't have an inventory yet!\nDo `tf.unbox` to get started!**", value = "<@" + str(ctx.author.id)+">") await ctx.send(embed=userNotFound, delete_after=10) else: if True == (str(args)[5:-4].isdecimal()): itemSrv.execute("SELECT count(name) FROM sqlite_master WHERE type='table' AND name='"+str(args)[5:-4]+"'") if int(itemSrv.fetchone()[0]) == 0: print("\nUser ID #"+str(ctx.author.id)+" requested to see the inventory of user ID#"+str(args)[5:-4]+" but they have no items") error = True userNotFound = discord.Embed(title = "", color = discord.Colour.red()) userNotFound.add_field(name = '**User not found!**', value = "<@" + str(ctx.author.id)+">") await ctx.send(embed=userNotFound, delete_after=10) else: print("\nUser ID #"+str(ctx.author.id)+" requested to see the inventory of user ID#"+str(args)[5:-4]) someoneElse = True inventory = discord.Embed(title = "", color = discord.Colour.blue()) itemSrv.execute("SELECT * FROM '"+ str(args)[5:-4]+"'") else: print("\nUser ID #"+str(ctx.author.id)+" requested to see the inventory of user ID#"+str(args)[5:-4]+" but they have no items") error = True userNotFound = discord.Embed(title = "", color = discord.Colour.red()) userNotFound.add_field(name = '**User not found!**', value = "<@" + str(ctx.author.id)+">") await ctx.send(embed=userNotFound, delete_after=10) # except: # error = True items = "" if error == False: if someoneElse == True: itemSrv.execute("SELECT * FROM '"+str(str(args)[5:-4])+"' ORDER BY items") else: itemSrv.execute("SELECT * FROM '"+str(ctx.author.id)+"' ORDER BY items") for x in itemSrv.fetchall(): items = items + str(x)[2:-3] + "\n" if someoneElse == False: inventory.add_field(name = '**Your inventory:**', value = "<@" + str(ctx.author.id)+">\n\n"+items) else: inventory.add_field(name = '**Other inventory:**', value = "<@" + str(args)[5:-4]+">'s Inventory\n\n"+items) await ctx.send(embed=inventory, delete_after=120) @inventory.error async def inventory_error(ctx, error): embedTooLong = discord.Embed(title = "", color = discord.Colour.red()) embedTooLong.add_field(name = '**An error has occured while checking inventory**', value = "<@" + str(ctx.author.id)+">") await ctx.send(embed=embedTooLong, delete_after=10) @client.command() async def trade(ctx, *args): try: if str(args) == "()": testing = discord.Embed(title = "", color = discord.Colour.green()) testing.add_field(name = '**Instructions have been sent to you**', value = "<@" + str(ctx.author.id)+">") await ctx.send(embed=testing, delete_after=5) user= client.get_user(ctx.author.id) testing = discord.Embed(title = "", color = discord.Colour.green()) testing.add_field(name = '**Trading**', value = "Please enter the users discord ID (NOT their username)\n\nAlternatively, you can tag them in the trade message inside of a server.") testingEmbed = await user.send(embed=testing) error = False await asyncio.sleep(0.5) msg = await client.wait_for("message") await testingEmbed.delete() player = msg.content else: if True == (str(args)[5:-4].isdecimal()): player = int(str(args)[5:-4]) error = False user= client.get_user(ctx.author.id) else: failedTag = discord.Embed(title = "", color = discord.Colour.red()) failedTag.add_field(name = '**Please tag someone to trade.**', value = "<@" + str(ctx.author.id)+">") await ctx.send(embed=failedTag, delete_after=10) error = True if str(player) != str(ctx.author.id): itemSrv.execute("SELECT count(name) FROM sqlite_master WHERE type='table' AND name='"+str(player)+"'") if int(itemSrv.fetchone()[0]) == 0: print("\nUser ID #"+str(ctx.author.id)+" requested to see the inventory of user ID#"+str(player)+" but they have no items") error = True userNotFound = discord.Embed(title = "", color = discord.Colour.red()) userNotFound.add_field(name = '**User not found!**', value = "<@" + str(ctx.author.id)+">") await user.send(embed=userNotFound, delete_after=10) else: print("\nUser ID #"+str(ctx.author.id)+" requested to see the inventory of user ID#"+str(player)) someoneElse = True inventory = discord.Embed(title = "", color = discord.Colour.blue()) itemSrv.execute("SELECT * FROM '"+ str(player)+"'") items = "" itemsList = [] if error == False: itemSrv.execute("SELECT * FROM '"+str(player)+"' ORDER BY items") for x in itemSrv.fetchall(): if "[Untradeable]" and "[Untradable]" not in str(x)[2:-3]: items = items + str(x)[2:-3] + "\n" itemsList.append(str(x)[2:-3]) inventory.add_field(name = '**Other inventory:**', value = "<@" + str(player)+">'s Inventory\n\n"+items) # await ctx.send(embed=inventory) # inventory = discord.Embed(title = "", color = discord.Colour.blue()) itemSrv.execute("SELECT count(name) FROM sqlite_master WHERE type='table' AND name='"+str(ctx.author.id)+"'") if int(itemSrv.fetchone()[0]) != 0: itemSrv.execute("SELECT * FROM '"+ str(ctx.author.id)+"'") print("\nUser ID #"+str(ctx.author.id)+" requested to see their inventory") else: print("\nUser ID #"+str(ctx.author.id)+" requested to see their inventory, but they don't have any items") error = True userNotFound = discord.Embed(title = "", color = discord.Colour.red()) userNotFound.add_field(name = "**You don't have an inventory yet!\nDo `tf.unbox` to get started!**", value = "<@" + str(ctx.author.id)+">") await user.send(embed=userNotFound, delete_after=10) uitems = "" uitemsList = [] itemSrv.execute("SELECT * FROM '"+str(ctx.author.id)+"' ORDER BY items") for x in itemSrv.fetchall(): if "[Untradeable]" and "[Untradable]" not in str(x)[2:-3]: uitems = uitems + str(x)[2:-3] + "\n" uitemsList.append(str(x)[2:-3]) howto = discord.Embed(title = "", color = discord.Colour.green()) howto.add_field(name = '**How to trade:**', value = "1. Type the items you want to receive out of their inventory\n2. Type `next` to confirm\n3. Type the items you want send to them from your inventory\n4. Type `send` to send the trade\n\n**You can triple-click the text to highlight and copy it**") how2Trade = await user.send(embed=howto) inventory.add_field(name = '**Your inventory:**', value = "<@" + str(ctx.author.id)+">\n\n"+uitems) inventoryEmbed = await user.send(embed=inventory) send = discord.Embed(title = "", color = discord.Colour.green()) send.add_field(name = '**Send**', value = "None") receive = discord.Embed(title = "", color = discord.Colour.green()) receive.add_field(name = '**Receive**', value = "None") await asyncio.sleep(0.5) receiveEmbed = await user.send(embed=receive) await asyncio.sleep(0.5) sendEmbed = await user.send(embed=send) currentSend = [] currentReceive = [] currentSendText = "" currentReceiveText = "" await asyncio.sleep(1) msg = await client.wait_for("message") if msg.content in itemsList: currentReceive.append(msg.content) currentReceiveText = currentReceiveText + str(msg.content) + "\n" receive.clear_fields() receive.add_field(name = '**Receive**', value = currentReceiveText) await receiveEmbed.edit(embed=receive) while msg.content != "next": msg = await client.wait_for("message", check=lambda message: message.author == ctx.author and isinstance(message.channel, discord.DMChannel)) if msg.content in itemsList and currentReceive.count(msg.content) < itemsList.count(msg.content): currentReceive.append(msg.content) currentReceiveText = currentReceiveText + str(msg.content) + "\n" receive.clear_fields() receive.add_field(name = '**Receive**', value = currentReceiveText) await receiveEmbed.edit(embed=receive) while msg.content != "send": msg = await client.wait_for("message", check=lambda message: message.author == ctx.author and isinstance(message.channel, discord.DMChannel)) if msg.content in uitemsList and currentSend.count(msg.content) < uitemsList.count(msg.content): currentSend.append(msg.content) currentSendText = currentSendText + msg.content + "\n" send.clear_fields() send.add_field(name = '**Send**', value = currentSendText) await sendEmbed.edit(embed=send) await inventoryEmbed.delete() await receiveEmbed.delete() await sendEmbed.delete() await how2Trade.delete() confirmSend = discord.Embed(title = "", color = discord.Colour.purple()) if currentSendText != "" or currentReceiveText != "": if currentSendText == "": currentSendText = "Nothing" if currentReceiveText == "": currentReceiveText = "Nothing" def check(reaction, user): return reaction.message.id == confirm.id confirmSend.add_field(name = '**Please confirm the trade.**', value = "\n**You will get:**\n`"+currentReceiveText+"`\n**You will lose:**\n`"+currentSendText+"`\n\n**All trades are final!\nOffer cannot be cancelled once sent.**") confirm = await user.send(embed=confirmSend) await confirm.add_reaction("✅") await confirm.add_reaction("❌") await asyncio.sleep(1) reaction = await client.wait_for("reaction_add",check=check) if str(reaction[0]) == "✅": print("User ID #"+str(ctx.author.id)+" sent a trade to User ID #"+str(player)+"\n"+currentSendText+"\nfor\n"+currentReceiveText) confirmSend = discord.Embed(title = "", color = discord.Colour.green()) confirmSend.add_field(name = '**Trade sent!**', value = "Your trade to <@" + str(player)+"> has been sent.") confirm = await user.send(embed=confirmSend) userDm = await client.fetch_user(int(player)) confirmSend = discord.Embed(title = "", color = discord.Colour.green()) confirmSend.add_field(name = '**User wants to trade:**', value = "<@" + str(ctx.author.id)+">"+" wants to trade with you.\n\n**You will lose:**\n`"+currentReceiveText+"`\n**You will get:**\n`"+currentSendText+"`\n\n**All trades are final!**") confirm = await userDm.send(embed=confirmSend) await confirm.add_reaction("✅") await confirm.add_reaction("❌") await asyncio.sleep(1) reaction = await client.wait_for("reaction_add",check=check) if str(reaction[0]) == "✅": itemsList = [] itemSrv.execute("SELECT * FROM '"+str(player)+"' ORDER BY items") for x in itemSrv.fetchall(): if "[Untradeable]" and "[Untradable]" not in str(x)[2:-3]: items = items + str(x)[2:-3] + "\n" itemsList.append(str(x)[2:-3]) uitemsList = [] itemSrv.execute("SELECT * FROM '"+str(ctx.author.id)+"' ORDER BY items") for x in itemSrv.fetchall(): if "[Untradeable]" and "[Untradable]" not in str(x)[2:-3]: uitems = uitems + str(x)[2:-3] + "\n" uitemsList.append(str(x)[2:-3]) receiveChecksOut = False sendChecksOut = False if currentSendText == "Nothing": sendChecksOut = True if currentReceiveText == "Nothing": receiveChecksOut = True for x in currentReceive: count=0 for y in itemsList: if x == y: count+=1 if count >= currentReceive.count(x): receiveChecksOut = True else: receiveChecksOut = False for x in currentSend: count=0 for y in uitemsList: if x == y: count+=1 if count >= currentReceive.count(x): sendChecksOut = True else: sendChecksOut = False if sendChecksOut and receiveChecksOut: print("User ID #"+str(player)+" accepted User ID #"+str(ctx.author.id)+"'s trade request") now = datetime.now() now = now.strftime('%d/%m/%Y %H:%M:%S') if currentSendText != "Nothing": for x in currentSend: itemSrv.execute("INSERT INTO '"+str(player)+"'(items) VALUES('"+x+"')") itemSrv.execute("DELETE FROM '"+str(ctx.author.id)+"' WHERE items='"+x+"' AND rowid = (SELECT MIN(rowid) FROM '"+str(ctx.author.id)+"' WHERE items='"+x+"')") if currentReceiveText != "Nothing": for x in currentReceive: itemSrv.execute("INSERT INTO '"+str(ctx.author.id)+"'(items) VALUES('"+x+"')") itemSrv.execute("DELETE FROM '"+str(player)+"' WHERE items='"+x+"' AND rowid = (SELECT MIN(rowid) FROM '"+str(player)+"' WHERE items='"+x+"')") conn.commit() tradeID = random.randint(1111111111111111111111,9999999999999999999999) tradeDocument = open("trades.txt","a") tradeDocument.write("Trade ID #"+str(tradeID)+"\n"+str(ctx.author.id)+" sent a trade to "+str(player)+", who accepted on "+now+"\nPlayer sent:\n"+currentSendText+"\nPlayer received:\n"+currentReceiveText+"\n") tradeDocument.close() userNotFound = discord.Embed(title = "", color = discord.Colour.green()) userNotFound.add_field(name = '**Trade accepted!**', value = "New items:\n`"+currentReceiveText+"`\n("+now+")") userNotFound.set_footer(text="Trade ID #"+str(tradeID)) await user.send(embed=userNotFound) userNotFound = discord.Embed(title = "", color = discord.Colour.green()) userNotFound.add_field(name = '**You accepted the trade.**', value = "New items:\n`"+currentSendText+"`\n("+now+")") userNotFound.set_footer(text="Trade ID #"+str(tradeID)) await userDm.send(embed=userNotFound) else: await confirm.delete() confirmSend = discord.Embed(title = "", color = discord.Colour.red()) confirmSend.add_field(name = '**Trade failed.**', value = "Items in the trade are no longer available.") confirm = await user.send(embed=confirmSend, delete_after=10) await confirm.delete() confirmSend = discord.Embed(title = "", color = discord.Colour.red()) confirmSend.add_field(name = '**Trade failed.**', value = "Items in the trade are no longer available.") confirm = await userDm.send(embed=confirmSend, delete_after=10) else: print("User ID #"+str(player)+" declined User ID #"+str(ctx.author.id)+"'s trade request") userNotFound = discord.Embed(title = "", color = discord.Colour.red()) now = datetime.now() now = now.strftime('%d/%m/%Y %H:%M:%S') userNotFound.add_field(name = '**Trade declined.**', value = "You declined "+"<@" + str(ctx.author.id)+">"+"'s trade\n("+now+")") await userDm.send(embed=userNotFound) userNotFound = discord.Embed(title = "", color = discord.Colour.red()) userNotFound.add_field(name = '**Trade declined.**', value = "<@" + str(player)+"> declined your trade.\n("+now+")") await user.send(embed=userNotFound) else: await confirm.delete() confirmSend = discord.Embed(title = "", color = discord.Colour.red()) confirmSend.add_field(name = '**Trade cancelled.**', value = "Your trade did not get sent.") confirm = await user.send(embed=confirmSend, delete_after=10) else: confirmSend = discord.Embed(title = "", color = discord.Colour.red()) confirmSend.add_field(name = '**Trade is empty.**', value = "You didn't enter an item to trade\nso there is no point in sending the offer.") confirm = await user.send(embed=confirmSend, delete_after=10) else: confirmSend = discord.Embed(title = "", color = discord.Colour.red()) confirmSend.add_field(name = '**You cannot trade with yourself.**', value = "The ID you requested to trade with is your ID.") confirm = await user.send(embed=confirmSend, delete_after=10) except asyncio.TimeoutError: confirmSend = discord.Embed(title = "", color = discord.Colour.red()) confirmSend.add_field(name = '**Timed out**', value = "You took too long to respond.") confirm = await user.send(embed=confirmSend, delete_after=10) # @trade.error # async def trade_error(ctx,error): # confirmSend = discord.Embed(title = "", color = discord.Colour.red()) # confirmSend.add_field(name = '**Something went wrong.**', value = "An unknown error occured while trading.\nPlease try again.") # confirm = await ctx.send(embed=confirmSend, delete_after=5) @client.command() async def collectors(ctx): testing = discord.Embed(title = "", color = discord.Colour.green()) testing.add_field(name = '**Instructions have been sent to you**', value = "<@" + str(ctx.author.id)+">") await ctx.send(embed=testing, delete_after=5) error = False user= client.get_user(ctx.author.id) itemSrv.execute("SELECT count(name) FROM sqlite_master WHERE type='table' AND name='"+str(ctx.author.id)+"'") if int(itemSrv.fetchone()[0]) != 0: itemSrv.execute("SELECT * FROM '"+str(ctx.author.id)+"' ORDER BY items") uitems = "" uitemsList = [] for x in itemSrv.fetchall(): uitems = uitems + str(x)[2:-3] + "\n" uitemsList.append(str(x)[2:-3]) print("\nUser ID #"+str(ctx.author.id)+" requested to see their inventory") else: print("\nUser ID #"+str(ctx.author.id)+" requested to see their inventory, but they don't have any items") error = True userNotFound = discord.Embed(title = "", color = discord.Colour.red()) userNotFound.add_field(name = "**You don't have an inventory yet!\nDo `tf.unbox` to get started!**", value = "<@" + str(ctx.author.id)+">") await user.send(embed=userNotFound, delete_after=10) if error == False: inventory = discord.Embed(title = "", color = discord.Colour.blue()) inventory.add_field(name = '**Your inventory:**', value = "<@" + str(ctx.author.id)+">\n\n"+uitems) inventoryEmbed = await user.send(embed=inventory) testing = discord.Embed(title = "", color = discord.Colour.green()) testing.add_field(name = '**Collectors**', value = "Please enter items to make into a collectors item.\n(You need 10 unique copies [but not necessarily unique quality])") testingEmbed = await user.send(embed=testing) await asyncio.sleep(0.5) msg = await client.wait_for("message", check=lambda message: message.author == ctx.author and isinstance(message.channel, discord.DMChannel)) await testingEmbed.delete() await inventoryEmbed.delete() itemToCollectors = msg.content if msg.content in uitemsList: if uitemsList.count(msg.content) >= 10: count=0 textStuff = "" while count != 10: textStuff = textStuff+itemToCollectors+"\n" count+=1 print(textStuff) def check(reaction, user): return reaction.message.id == confirm.id confirmSend = discord.Embed(title = "", color = 0xAA0000) confirmSend.add_field(name = '**Please confirm collectors process**', value = "\n**You will get:**\n`Collectors "+itemToCollectors+"`\n**You will lose:**\n`"+textStuff+"`\n\n**This process is irreversible**") confirm = await user.send(embed=confirmSend) await confirm.add_reaction("✅") await confirm.add_reaction("❌") await asyncio.sleep(1) reaction = await client.wait_for("reaction_add",check=check) if str(reaction[0]) == "✅": await confirm.delete() count = 0 while count != 10: itemSrv.execute("DELETE FROM '"+str(ctx.author.id)+"' WHERE items='"+itemToCollectors+"' AND rowid = (SELECT MIN(rowid) FROM '"+str(ctx.author.id)+"' WHERE items='"+itemToCollectors+"')") count+=1 itemToCollectors = "Collectors "+itemToCollectors itemSrv.execute("INSERT INTO '"+str(ctx.author.id)+"'(items) VALUES('"+itemToCollectors+"')") conn.commit() collectors = discord.Embed(title = "", color = 0xAA0000) collectors.add_field(name = '**Collectors Succeeded**', value = "New item:\n`"+itemToCollectors+"`") await user.send(embed=collectors) else: await confirm.delete() userNotFound = discord.Embed(title = "", color = discord.Colour.red()) userNotFound.add_field(name = "**Collectors item failed**", value = "You cancelled the process") await user.send(embed=userNotFound, delete_after=5) else: userNotFound = discord.Embed(title = "", color = discord.Colour.red()) userNotFound.add_field(name = "**Collectors item failed**", value = "You don't have 10 unique copies of that item") await user.send(embed=userNotFound, delete_after=5) else: userNotFound = discord.Embed(title = "", color = discord.Colour.red()) userNotFound.add_field(name = "**Collectors item failed**", value = "That item isn't in your inventory") await user.send(embed=userNotFound, delete_after=5) @client.command() async def give(ctx, args): if int(ctx.author.id) == 495976318274502676 or int(ctx.author.id) == 123968463453552644: player = args userDm = await client.fetch_user(int(player)) user= client.get_user(ctx.author.id) userNotFound = discord.Embed(title = "", color = discord.Colour.green()) userNotFound.add_field(name = "**Enter item**", value = "Enter item to give") embed = await user.send(embed=userNotFound) await asyncio.sleep(1) msg = await client.wait_for("message", check=lambda message: message.author == ctx.author and isinstance(message.channel, discord.DMChannel)) def check(reaction, user): return reaction.message.id == confirm.id confirm = discord.Embed(title = "", color = discord.Colour.green()) confirm.add_field(name = '**Please confirm action**', value = "\n**Player to give item to:**\n`"+str(player)+"`\n**Item to give:**\n`"+msg.content+"`") confirm = await user.send(embed=confirm) await embed.delete() await confirm.add_reaction("✅") await confirm.add_reaction("❌") await asyncio.sleep(1) reaction = await client.wait_for("reaction_add",check=check) if str(reaction[0]) == "✅": await confirm.delete() userNotFound = discord.Embed(title = "", color = discord.Colour.teal()) userNotFound.add_field(name = '**Support granted you:\n||'+msg.content+'||**', value = "<@" + str(player)+">") embed = await userDm.send(embed=userNotFound) itemSrv.execute("INSERT INTO '"+str(player)+"'(items) VALUES('"+msg.content+"')") conn.commit() else: userNotFound = discord.Embed(title = "", color = discord.Colour.red()) userNotFound.add_field(name = "**Cancelled**", value = "Item didnt send.") await user.send(embed=userNotFound, delete_after=5) client.run('replaceme')