Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi Guys, I need some help. So.. ive been developing a discord bot over the last year and trying to make some improvements to the

Hi Guys, I need some help. So.. ive been developing a discord bot over the last year and trying to make some improvements to the games i have made.. it is basically an economy system that allows users to transfer funds to one another, place bets, and recieve winnings etc. I have created a slots game that automatically generates winnings and economy but my idea is to modify an exisiting heads or tails game with the same functions to basically:

Allow a user to deposit a bet into an account that holds the winnings/profits/bets etc.

The user will then either select heads or tails to win the challenge.

The winnings will then be transferred directly from the specific account.

My current code is:

mport discord import random from discord.ext import commands from discord.ext import commands, tasks from discord.ui import select, View from discord.embeds import Embed from discord import colour import asyncio from itertools import cycle import os import json import datetime from random import choice intents = discord.Intents.default() intents.message_content = True client = commands.Bot(command_prefix='!', intents=intents) #Command prefix #Notifies vs code that the bot is running on VS code# @client.event async def on_ready(): print("Bot is ready") #Slot machine command when user enters !slots 50# @client.command(pass_context=True) async def slots(ctx, amount=None): if amount == None: em = discord.Embed(title=f'Please enter an amount',color = discord.Color.red()) em.timestamp = datetime.datetime.utcnow() await ctx.send(embed= em) return bal = await update_bank(ctx.author) amount = int(amount) if amount > bal[0]: em = discord.Embed(title=f'You do not have sufficient balance') em.timestamp = datetime.datetime.utcnow() await ctx.send(embed= em) return if amount < 0: em = discord.Embed(title=f'Amount must be positive') em.timestamp = datetime.datetime.utcnow() await ctx.send(embed= em) return slots = ['', ''] slot1 = slots[random.randint(0, 1)] slotOutput = '| :{}: | '.format(slot1) ok = discord.Embed(title = "RTC slot machine", color = discord.Color(0xFFEC)) ok.add_field(name = "{} Won".format(slotOutput), value = f'You won {1.9*amount} coins') won = discord.Embed(title = "Slots Machine", color = discord.Color(0xFFEC)) won.add_field(name = "{} Won".format(slotOutput), value = f'You won {1.9*amount} coins') if slot1: await update_bank(ctx.author, 1.9 * amount) await ctx.send(embed = won) return 
The deposit bet command for the agreed bet when user enters !db @hostname 500 for example# @client.command() async def db(ctx,member : discord.Member,amount = None): await open_account(ctx.author) await open_account(member) if amount == None: em = discord.Embed(title=f'Please enter an amount you wish to bet',color = discord.Color.red()) em.timestamp = datetime.datetime.utcnow() await ctx.send(embed= em) return bal = await update_bank(ctx.author) if amount == 'all': amount = bal[0] amount = int(amount) if amount > bal[0]: em = discord.Embed(title=f'You do not have sufficient balance',color = discord.Color.red()) em.timestamp = datetime.datetime.utcnow() await ctx.send(embed= em) return if amount < 0: em = discord.Embed(title =f'Amount must be positive',color = discord.Color.red()) em.timestamp = datetime.datetime.utcnow() await ctx.send(embed= em) return await update_bank(ctx.author,-1*amount,'wallet') await update_bank(member,amount,'bank') em = discord.Embed(title=f'{ctx.author.name} sent {amount}M RS3 to {member}', description=f'Please select the game/challenge !coinflip !elements or !yesandno',color = discord.Color.green()) em.timestamp = datetime.datetime.utcnow() await ctx.send(embed= em) 
#Creates account details for member of the channel# async def open_account(user): users = await get_bank_data() if str(user.id) in users: return False else: users[str(user.id)] = {} users[str(user.id)]["wallet"] = 0 users[str(user.id)]["bank"] = 0 with open('bank.json','w') as f: json.dump(users,f) return True #Stores the user wallet amount in the bank.json file# async def get_bank_data(): with open('bank.json','r') as f: users = json.load(f) return users #Updates the users bank details held within the json file. async def update_bank(user,change=0,mode = 'wallet'): users = await get_bank_data() users[str(user.id)][mode] += change with open('bank.json','w') as f: json.dump(users,f) bal = users[str(user.id)]['wallet'],users[str(user.id)]['bank'] return bal client.run("'''''") 

Im looking for a way to modify the code so it takes the winnings from a specific account by implimenting the account ID or username.

Any ideas?`

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions