-2

I have this code:

#rob
@client.command()
@commands.cooldown(1,10800,commands.BucketType.user)
async def rob(ctx,member:discord.User = None):
  if member == None:
    em = discord.Embed(title='ERROR:', description='Please specify a member you want to rob!', color=0xff0000)
  await ctx.send(embed = em) 
  return

  await open_account(ctx.author)
  await open_account(member)
    
  bal = await update_bank(member)

  if bal[0]<50:
    em = discord.Embed(title='ERROR:', description="The member you try to rob doesn't have that much money!", color=0xff0000)
  await ctx.send(embed = em) 
  return 
  
  if amount<0:
    em = discord.Embed(title='ERROR:', description="Amount must be positive!", color=0xff0000)
  await ctx.send(embed = em) 
  return 
    
  earnings = random.randrange(0, bal[100])
  fine = random.randrange(0, bal[100])

  em1 = discord.Embed(title='Succesfully robbed!', description=f"You robbed {earnings} coins!", color=0x00ff00)
  em2 = discord.Embed(title='Caught!', description=f"You got caught! You paid a {fine} coins fine! ", color=0x00ff00)

  yesorno = random.randrange(0, 1)
  if yesorno == 1:
      await ctx.send(embed = em1)
      await update_bank(ctx.author,earnings)
      await update_bank(member,-1*earnings)
  else:
      await ctx.send(embed = em2)
      await update_bank(ctx.author,-1*fine)

This function's goal is to rob someone and take their money or give them a fine, but it doesn't work. It doesn't send em1 or em2, I don't know how to fix it. I tried many things, but it doesn't give an error!

  • 3
    Are you sure your indentation is correct? If you put `return` in the middle of your code the way it's indented here, you would only get up to the first `await ctx.send(embed=em)`. Please check your indentation, thanks. – Bagle Mar 25 '22 at 02:49
  • @Bagle Still doesnt work... And still doesnt give any error. – ThisBadTeamate Mar 25 '22 at 16:48
  • Do you have an `on_message` event anywhere? If you did not [process commands](https://stackoverflow.com/a/49839338/14420546) then none of your commands will work. Otherwise, do try using `print` throughout your code to see if your command runs at all (debugging). – Bagle Mar 26 '22 at 02:38
  • @Bagle yesorno function didnt work and messed up the whole ctx.send... Works fine now. Thanks! – ThisBadTeamate Mar 26 '22 at 17:10
  • Instead of writing "(closed)", you should write your own answer and accept it, just a heads up – Bagle Mar 27 '22 at 02:38
  • 1
    @Bagle Alright thanks! – ThisBadTeamate Mar 27 '22 at 13:27

1 Answers1

0

What fixed it for me was changing the yesorno function. Changed it to:

 yesorno = random.randrange(0, 2)
  if yesorno == 1:
    await ctx.send(embed = em1)
    await update_bank(ctx.author,1*earnings)
    await update_bank(member,-1*earnings)
  else:
    await ctx.send(embed = em2)
    await update_bank(ctx.author,-1*fine)
    await update_bank(member,1*fine)