Getting user mentioned's “XP”. JSON, Discord.py

Getting user mentioned's “XP”. JSON, Discord.py



I'm trying to make a command where users can steal other user's XP (dollars). I'm using random.randintto make it so they are either successful or not, but I want to do a check to make sure the user that is being mentioned(robbed) has enough XP (dollars) for the author to steal. I've tried a few ways such as if (get_dollars(message.mentions[0].id) < 25:and if (get_dollars(user.mention.id) < 25: with no success. Here's the "full" code:


random.randint


if (get_dollars(message.mentions[0].id) < 25:


if (get_dollars(user.mention.id) < 25:


client = discord.Client()

try:
with open("cash.json") as fp:
cash = json.load(fp)
except Exception:
cash =

def save_cash():
with open("cash.json", "w+") as fp:
json.dump(cash, fp, sort_keys=True, indent=4)

def add_dollars(user: discord.User, dollars: int):
id = user.id
if id not in cash:
cash[id] =
cash[id]["dollars"] = cash[id].get("dollars", 0) + dollars
print(" now has dollars".format(user.name, cash[id]["dollars"]))
save_cash()

def remove_dollars(user: discord.User, dollars: int):
id = user.id
if id not in cash:
cash[id] =
cash[id]["dollars"] = cash[id].get("dollars", 0) - dollars
print(" now has dollars".format(user.name, cash[id]["dollars"]))
save_cash()

def get_dollars(user: discord.User):
id = user.id
if id in cash:
return cash[id].get("dollars", 0)
return 0

@client.event
async def on_message(message):
steal = random.randint(1,3)
stealdollars = random.randint(25, 250)
if message.content.startswith('!rob'):
user = message.mentions[0]
if (get_dollars(user.mention)) < 25:
await client.send_message(message.channel, " is too broke to rob 🤣".format(user.mention))
elif steal == 1:
print(" catches slippin and sticks them up for $ 😨🔫".format(message.author.mention, user.metion, stealdollars))
await client.send_message(message.channel, " catches slippin and sticks them up for $ 😨🔫".format(message.author.mention, user.mention, stealdollars))
remove_dollars(user.mention, stealdollars)
add_dollars(message.author, stealdollars)
elif steal == 2:
print(" kicks 's door down but doesn't find any cash 🤦‍".format(message.author.mention, user.mention))
await client.send_message(message.channel, " kicks 's door down but doesn't find any cash".format(message.author.mention, user.metion))
elif steal == 3:
print(" gets arrested trying to rob and has to post $250 bail 👮🚨".format(message.author.mention, user.metion))
await client.send_message(message.channel, " gets arrested trying to rob and has to post $250 bail 👮🚨".format(message.author.mention, user.metion))
remove_dollars(message.author, 250)




1 Answer
1



Sorry had a brain fart. I ended up using


for user in message.mentions:
if (get_dollars(user)) < 25:



Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ

Node.js puppeteer - Use values from array in a loop to cycle through pages