Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @bot.command(
- type=interactions.ApplicationCommandType.CHAT_INPUT,
- name="buy",
- scope=934127207872331787,
- description="buy a stock",
- options=[interactions.Option(
- type=interactions.OptionType.STRING,
- name="symbol",
- description="symbol of stock",
- autocomplete=True,
- required =True
- )]
- )
- async def buy(ctx, symbol):
- pr = h.price(symbol)
- try:
- data = check(int(ctx.author.user.id))
- except:
- await ctx.send("This stock doesnt exist")
- return
- am = int(str(data["wallet"]/float(pr)).split(".")[0])
- if am < 1:
- sr = "you do not have enough money to buy this stock"
- n = True
- else:
- sr = f"you can buy a max of {am} {symbol} stock(s)"
- n = False
- if n:
- await ctx.send(sr, ephemeral=True)
- return
- await ctx.send(f"This stock costs ${pr} each \n {sr} \n (0 for none)")
- async def checks(msg):
- if int(msg.author.id) == int(ctx.author.user.id):
- return True
- await ctx.send("I wasn't asking you", ephemeral=True)
- return False
- try:
- msg: Message = await wait_for.wait_for(
- bot, "on_message_create", check=checks, timeout=15
- )
- try:
- t = int(str(msg.content))
- except:
- await ctx.send(f"Must be a number and contain no decimals, not {msg.content} \ntry again")
- return
- if 1 > t:
- await ctx.send("Buy canceled")
- return
- else:
- n = await ctx.send(f"Do you wish to buy {t} {symbol} with a total cost of {t*float(pr)}?", components=yn)
- button_ctx: ComponentContext = await bot.wait_for_component(
- components=[yny, ynn], check=check, timeout=15
- )
- print(n._json)
- await n.delete()
- if button_ctx.custom_id == 'yes':
- await ctx.send("Buying and stuff")
- return
- else:
- return await ctx.send("Cancled", ephemeral=True)
- except asyncio.TimeoutError:
- return await ctx.send("You said nothing :(")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement